]> git.itanic.dy.fi Git - rrdd/commitdiff
rrdtool_update_data_multi: Discard entries with timestamp in future
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sun, 25 Oct 2020 16:13:58 +0000 (18:13 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sun, 25 Oct 2020 16:13:58 +0000 (18:13 +0200)
If parser data contains entries with timestamp in future, they should
be discarded. If such entries are allowed to be put into the rrd
database, the database will refuse to accept any more any entries,
untill current date is again above the corrupted date. Depending on
the severity of the corruption, this might prevent any further updates
to the database.

Therefore it is better to not allow any updates from future.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
rrdtool.c

index 98844c596af11ed0d9dc5061d11507a996a2950e..ece5d12d7d5485954ab779b326d874fc2a79c6d4 100644 (file)
--- a/rrdtool.c
+++ b/rrdtool.c
@@ -276,6 +276,7 @@ static int rrdtool_update_data_multi(struct rrd_database *rrd)
                (char *const)rrd->filename,
        };
        int old_last_update = rrd->last_update;
+       time_t now = time(NULL);
 
        ret = rrd->parser->parse_multi(&data, rrd->parser_data,
                                &rrd->parser_state, rrd->last_update);
@@ -284,7 +285,7 @@ static int rrdtool_update_data_multi(struct rrd_database *rrd)
                goto out;
        }
 
-       for (i = 3, d = 0; i < ARRAY_SIZE(cmdline) - 1; i++, d++) {
+       for (i = 3, d = 0; i < ARRAY_SIZE(cmdline) - 1; d++) {
                time_t then;
 
                if (!data[d])
@@ -293,11 +294,17 @@ static int rrdtool_update_data_multi(struct rrd_database *rrd)
                sanitize_rrd_update_data(data[d]);
 
                then = atoi(data[d]);
+               if (then > now) {
+                       pr_err("Skipping bad data with timestamp in future: %ld > %ld\n",
+                               then, now);
+                       continue;
+               }
                write_to_logfile(rrd, data[d], then);
                cmdline[i] = data[d];
                pr_info("Data: %s\n", data[d]);
 
                rrd->last_update = then;
+               i++;
        }
 
        cmdline[i] = 0;