5
0
mirror of git://git.proxmox.com/git/proxmox-backup.git synced 2025-03-05 20:58:33 +03:00

fix #4638: proxmox-backup-client: status: guard against div by zero

We throw an error if the value for total is zero.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
This commit is contained in:
Maximiliano Sandoval 2023-06-07 10:55:13 +02:00 committed by Dietmar Maurer
parent 73bd988c42
commit dae0b67f1f

View 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()