From d551ab2d74298583a124b4d437e1275b32ca7228 Mon Sep 17 00:00:00 2001 From: oetiker Date: Thu, 14 Jan 2010 13:01:43 +0000 Subject: [PATCH] new (better) checker for incoming COUNTER or DERIVED data. thanks Florian! git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.3@2001 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/src/rrd_update.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/program/src/rrd_update.c b/program/src/rrd_update.c index 1a6d2ef5..37da5eda 100644 --- a/program/src/rrd_update.c +++ b/program/src/rrd_update.c @@ -1022,24 +1022,22 @@ static int update_pdp_prep( switch (dst_idx) { case DST_COUNTER: case DST_DERIVE: - if ( ( updvals[ds_idx + 1][0] < '0' - || updvals[ds_idx + 1][0] > '9' ) - && updvals[ds_idx + 1][0] != '-' - && updvals[ds_idx + 1][0] != 'U' - ) { - rrd_set_error("not a simple integer: '%s'", - updvals[ds_idx + 1]); - return -1; - } - for (ii = 1; updvals[ds_idx + 1][ii] != '\0'; ii++) { - if ( updvals[ds_idx + 1][ii] < '0' - || updvals[ds_idx + 1][ii] > '9' - ) { - rrd_set_error("not a simple integer: '%s'", - updvals[ds_idx + 1]); + /* Check if this is a valid integer. `U' is already handled in + * another branch. */ + for (ii = 0; updvals[ds_idx + 1][ii] != 0; ii++) { + if ((ii == 0) && (dst_idx == DST_DERIVE) + && (updvals[ds_idx + 1][ii] == '-')) + continue; + + if ((updvals[ds_idx + 1][ii] < '0') + || (updvals[ds_idx + 1][ii] > '9')) { + rrd_set_error("not a simple %s integer: '%s'", + (dst_idx == DST_DERIVE) ? "signed" : "unsigned", + updvals[ds_idx + 1]); return -1; } - } + } /* for (ii = 0; updvals[ds_idx + 1][ii] != 0; ii++) */ + if (rrd->pdp_prep[ds_idx].last_ds[0] != 'U') { pdp_new[ds_idx] = rrd_diff(updvals[ds_idx + 1], -- 2.30.2