]> git.proxmox.com Git - proxmox-backup.git/commitdiff
rrd: fix integer underflow
authorStefan Reiter <s.reiter@proxmox.com>
Thu, 1 Oct 2020 09:40:44 +0000 (11:40 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 1 Oct 2020 12:30:32 +0000 (14:30 +0200)
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 <s.reiter@proxmox.com>
src/rrd/rrd.rs

index 8f542b528b550137f2c92eabbf2bc6d3a1654533..86d6b50b64bca6a11e4a0e1fb83b3e1c48b47808 100644 (file)
@@ -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;