]> git.proxmox.com Git - proxmox-backup.git/commitdiff
fix #4638: proxmox-backup-client: status: guard against div by zero
authorMaximiliano Sandoval <m.sandoval@proxmox.com>
Wed, 7 Jun 2023 08:55:13 +0000 (10:55 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 7 Jun 2023 09:21:52 +0000 (11:21 +0200)
We throw an error if the value for total is zero.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
proxmox-backup-client/src/main.rs

index 5519810861ce4f88df233f254621ecf56af4314e..5a804d95ecd43c771eec29da3446e74d3ef6b270 100644 (file)
@@ -1590,9 +1590,12 @@ async fn status(param: Value) -> Result<Value, Error> {
         let v = v.as_u64().unwrap();
         let total = record["total"].as_u64().unwrap();
         let roundup = total / 200;
-        let per = ((v + roundup) * 100) / total;
-        let info = format!(" ({} %)", per);
-        Ok(format!("{} {:>8}", v, info))
+        if let Some(per) = ((v + roundup) * 100).checked_div(total) {
+            let info = format!(" ({} %)", per);
+            Ok(format!("{} {:>8}", v, info))
+        } else {
+            bail!("Cannot render total percentage: denominator is zero");
+        }
     };
 
     let options = default_table_format_options()