From 4a1a8bfcda92a73538006b36ff6c93735b1dd06f Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sun, 25 Oct 2020 18:13:58 +0200 Subject: [PATCH] rrdtool_update_data_multi: Discard entries with timestamp in future 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 --- rrdtool.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rrdtool.c b/rrdtool.c index 98844c5..ece5d12 100644 --- 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; -- 2.44.0