From 0cc96ed702c3682fc02aeadade95450a508eedab Mon Sep 17 00:00:00 2001 From: Castulo Martinez Date: Tue, 11 Jun 2019 20:13:59 +0000 Subject: [PATCH] Adding a progress overflow protection When reporting download progress, we should never have a percentage bigger than 100%, but if for some reason we do (due to a bug), we don't want that percentage slipping all the way to the end user. This commit limits the percentage we display to 100 maximum. Signed-off-by: Castulo Martinez --- src/lib/progress.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/progress.c b/src/lib/progress.c index 3aae4e39..e8779a06 100644 --- a/src/lib/progress.c +++ b/src/lib/progress.c @@ -97,6 +97,13 @@ void progress_report(double count, double max) /* Only print when the percentage changes, so a maximum of 100 times per run */ int percentage = (int)(100 * (count / max)); + + /* we should never have a percentage bigger than 100% */ + if (percentage > 100) { + debug("Progress percentage overflow %d%% (Count: %ld, Max: %ld)\n", percentage, (long)count, (long)max); + return; + } + if (percentage != last_percentage || step.current != last_step) { if (progress_function) { progress_function(step.description, step.current, step.total, percentage);