[or-cvs] [tor/master] Fix two bugs found by Coverity scan.

Nick Mathewson nickm at seul.org
Tue Oct 20 03:19:41 UTC 2009


Author: Nick Mathewson <nickm at torproject.org>
Date: Mon, 19 Oct 2009 23:19:42 -0400
Subject: Fix two bugs found by Coverity scan.
Commit: afc76a4e714a192e76281793f39c412c87964e46

One was a simple buffer overrun; the other was a high-speed pointer
collision.  Both were introduced by my microdescs branch.
---
 src/common/container.c |   10 +++++-----
 src/or/dirvote.c       |    2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/common/container.c b/src/common/container.c
index 4fb94d3..f3540f7 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -470,26 +470,26 @@ smartlist_get_most_frequent(const smartlist_t *sl,
   const void *most_frequent = NULL;
   int most_frequent_count = 0;
 
-  const void **cur = NULL;
+  const void *cur = NULL;
   int i, count=0;
 
   if (!sl->num_used)
     return NULL;
   for (i = 0; i < sl->num_used; ++i) {
     const void *item = sl->list[i];
-    if (cur && 0 == compare(cur, &item)) {
+    if (cur && 0 == compare(&cur, &item)) {
       ++count;
     } else {
       if (cur && count >= most_frequent_count) {
-        most_frequent = *cur;
+        most_frequent = cur;
         most_frequent_count = count;
       }
-      cur = &item;
+      cur = item;
       count = 1;
     }
   }
   if (cur && count >= most_frequent_count) {
-    most_frequent = *cur;
+    most_frequent = cur;
     most_frequent_count = count;
   }
   return (void*)most_frequent;
diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index ca81b2b..5ce3fd2 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -2794,7 +2794,7 @@ ssize_t
 dirvote_format_microdesc_vote_line(char *out, size_t out_len,
                                    const microdesc_t *md)
 {
-  char d64[BASE64_DIGEST256_LEN];
+  char d64[BASE64_DIGEST256_LEN+1];
   if (!microdesc_consensus_methods) {
     microdesc_consensus_methods =
       make_consensus_method_list(MIN_METHOD_FOR_MICRODESC,
-- 
1.5.6.5



More information about the tor-commits mailing list