[evolution-data-server/evolution-data-server-3-12] camel: Avoid an unlikely division by zero on a race condition
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/evolution-data-server-3-12] camel: Avoid an unlikely division by zero on a race condition
- Date: Tue, 20 May 2014 10:12:59 +0000 (UTC)
commit 95adf1f9ad1388ef0d21d23e8c17ef06ecdb1f51
Author: Philip Withnall <philip withnall collabora co uk>
Date: Mon May 19 14:46:01 2014 +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.
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 c439b64..d9360ce 100644
--- a/camel/providers/local/camel-maildir-summary.c
+++ b/camel/providers/local/camel-maildir-summary.c
@@ -700,7 +700,14 @@ maildir_summary_check (CamelLocalSummary *cls,
while ((d = readdir (dir))) {
gchar *name, *newname, *destname, *destfilename;
gchar *src, *dest;
- 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]