[evolution-data-server] camel: Avoid an unlikely division by zero on a race condition



commit cc95f4518333e55dddbef7f6187a066cf5e6c841
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Sun May 10 11:26:10 2015 +0100

    camel: Avoid an unlikely division by zero on a race condition
    
    This is a subtle and really unlikely TOCTTOU race which Coverity found.
    Fix the potential division by zero which results from it.
    
    This fixes another instance of the original problem, fixed in commit
    8fb4543.
    
    Coverity issue: #1061271
    
    https://bugzilla.gnome.org/show_bug.cgi?id=730376

 camel/providers/local/camel-maildir-summary.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/camel/providers/local/camel-maildir-summary.c b/camel/providers/local/camel-maildir-summary.c
index 58c60c6..2831bfd 100644
--- a/camel/providers/local/camel-maildir-summary.c
+++ b/camel/providers/local/camel-maildir-summary.c
@@ -631,7 +631,14 @@ maildir_summary_check (CamelLocalSummary *cls,
        rewinddir (dir);
 
        while ((d = readdir (dir))) {
-               gint pc = count * 100 / total;
+               gint pc;
+
+               /* Avoid a potential division by zero if the first loop
+                * (to calculate total) is executed on an empty
+                * directory, then the directory is populated before
+                * this loop is executed. */
+               total = MAX (total, count + 1);
+               pc = (total > 0) ? count * 100 / total : 0;
 
                camel_operation_progress (cancellable, pc);
                count++;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]