Code

when using CDEF datasources in rrd, the rpnp in process_pdp_st (allocated in rpn_expa...
[rrdtool-all.git] / program / src / rrd_update.c
index 1a6d2ef52d712a62b15081b240911e89acc54352..200f412071b42e75688b40b13139df15d5213d75 100644 (file)
@@ -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],
@@ -1335,6 +1333,10 @@ static int process_pdp_st(
 
         rpnp =
             rpn_expand((rpn_cdefds_t *) &(rrd->ds_def[ds_idx].par[DS_cdef]));
+        if(rpnp == NULL) {
+          rpnstack_free(&rpnstack);
+          return -1;
+        }
         /* substitute data values for OP_VARIABLE nodes */
         for (i = 0; rpnp[i].op != OP_END; i++) {
             if (rpnp[i].op == OP_VARIABLE) {
@@ -1348,6 +1350,7 @@ static int process_pdp_st(
             rpnstack_free(&rpnstack);
             return -1;
         }
+        free(rpnp);
     }
 
     /* make pdp_prep ready for the next run */