From: Stefan Reiter Date: Thu, 1 Oct 2020 09:40:44 +0000 (+0200) Subject: rrd: fix integer underflow X-Git-Tag: v0.9.0~5 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=da6e67b32192bede9e580cfa46beb49183cee06e;p=proxmox-backup.git rrd: fix integer underflow Causes a panic if last_update is smaller than RRD_DATA_ENTRIES*reso, which (I believe) can happen when inserting the first value for a DB. Clamp the value to 0 in that case. Signed-off-by: Stefan Reiter --- diff --git a/src/rrd/rrd.rs b/src/rrd/rrd.rs index 8f542b52..86d6b50b 100644 --- a/src/rrd/rrd.rs +++ b/src/rrd/rrd.rs @@ -60,7 +60,7 @@ impl RRA { let min_time = epoch - (RRD_DATA_ENTRIES as u64)*reso; let min_time = (min_time/reso + 1)*reso; - let mut t = last_update - (RRD_DATA_ENTRIES as u64)*reso; + let mut t = last_update.saturating_sub((RRD_DATA_ENTRIES as u64)*reso); let mut index = ((t/reso) % (RRD_DATA_ENTRIES as u64)) as usize; for _ in 0..RRD_DATA_ENTRIES { t += reso; index = (index + 1) % RRD_DATA_ENTRIES;