Skip to content

Commit

Permalink
Merge pull request #1269 from TheWitness/master
Browse files Browse the repository at this point in the history
Fix #1268 - Segmentation Fault with Constant Lines
  • Loading branch information
oetiker authored Nov 17, 2024
2 parents 5041750 + 250d939 commit 637ad23
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Bugfixes
* Fix MacOS Build error (no SOCK_CLOEXEC on mac) @ensc fixes oetiker#1261
* Fix build on 32bits platforms (like armhf) when time_t is 64bits, fixes #1264
* Fix compilation on illumos @hadfl
* Fix issue where RRDtool detects a LINE or AREA with a constant numeric value as being exportable

Features
--------
Expand Down
52 changes: 39 additions & 13 deletions src/rrd_xport.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "rrd_snprintf.h"
#include "compat-cloexec.h"

int is_numeric(char *);

static int rrd_xport_fn(
image_desc_t *,
time_t *,
Expand Down Expand Up @@ -239,7 +241,21 @@ int rrd_xport(
return 0;
}

int is_numeric(char *instring) {
int c = 0;

if (*instring != '-' && *instring != '.' && !isdigit(*instring)) {
return 0;
}

if (strspn(instring+1, "0123456789.") < strlen(instring+1)) {
return 0;
}

while (*instring) if (*instring++ == '.') if (++c > 1) return 0;

return 1;
}

static int rrd_xport_fn(
image_desc_t *im,
Expand Down Expand Up @@ -280,15 +296,22 @@ static int rrd_xport_fn(
case GF_LINE:
case GF_AREA:
case GF_STACK:
(*col_cnt) += dolines;
/* only count the gf if it's numeric otherwise it's a constant line */
if (!is_numeric(im->gdes[i].vname)) {
(*col_cnt) += dolines;
}
break;
case GF_XPORT:
(*col_cnt)++;
/* only count the gf if it's numeric otherwise it's a constant line */
if (!is_numeric(im->gdes[i].vname)) {
(*col_cnt)++;
}
break;
default:
break;
}
}

if ((*col_cnt) == 0) {
rrd_set_error("no XPORT found, nothing to do");
return -1;
Expand Down Expand Up @@ -319,10 +342,14 @@ static int rrd_xport_fn(
case GF_LINE:
case GF_AREA:
case GF_STACK:
handle = dolines;
if (!is_numeric(im->gdes[i].vname)) {
handle = dolines;
}
break;
case GF_XPORT:
handle = 1;
if (!is_numeric(im->gdes[i].vname)) {
handle = 1;
}
break;
default:
handle = 0;
Expand Down Expand Up @@ -380,20 +407,19 @@ static int rrd_xport_fn(
}
dstptr = (*data);

long unsigned int chosen_idx = 0;

/* fill data structure */
for (dst_row = 0; (int) dst_row < (int) row_cnt; dst_row++) {
for (i = 0; i < (int) (*col_cnt); i++) {
long vidx = im->gdes[ref_list[i]].vidx;
time_t now = *start + dst_row * *step;
long vidx = im->gdes[ref_list[i]].vidx;
time_t now = *start + dst_row * *step;

(*dstptr++) = im->gdes[vidx].data[(unsigned long)
floor((double)
(now -
im->gdes[vidx].start)
/ im->gdes[vidx].step)
* im->gdes[vidx].ds_cnt +
im->gdes[vidx].ds];
if (im->gdes[vidx].step > 0) {
chosen_idx = floor((double) (now - im->gdes[vidx].start) / im->gdes[vidx].step) * im->gdes[vidx].ds_cnt + im->gdes[vidx].ds;

(*dstptr++) = im->gdes[vidx].data[chosen_idx];
}
}
}

Expand Down

0 comments on commit 637ad23

Please sign in to comment.