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

[or-cvs] r13598: Add a few asserts to catch possible errors found by veracode (in tor/trunk: . src/common src/or)



Author: nickm
Date: 2008-02-19 18:29:45 -0500 (Tue, 19 Feb 2008)
New Revision: 13598

Modified:
   tor/trunk/
   tor/trunk/src/common/container.c
   tor/trunk/src/or/config.c
   tor/trunk/src/or/routerparse.c
Log:
 r18230@catbus:  nickm | 2008-02-19 18:29:43 -0500
 Add a few asserts to catch possible errors found by veracode.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r18230] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/common/container.c
===================================================================
--- tor/trunk/src/common/container.c	2008-02-19 23:14:34 UTC (rev 13597)
+++ tor/trunk/src/common/container.c	2008-02-19 23:29:45 UTC (rev 13598)
@@ -90,6 +90,7 @@
 smartlist_add_all(smartlist_t *s1, const smartlist_t *s2)
 {
   smartlist_ensure_capacity(s1, s1->num_used + s2->num_used);
+  tor_assert(s1->capacity >= s1->num_used+s2->num_used);
   memcpy(s1->list + s1->num_used, s2->list, s2->num_used*sizeof(void*));
   s1->num_used += s2->num_used;
 }

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2008-02-19 23:14:34 UTC (rev 13597)
+++ tor/trunk/src/or/config.c	2008-02-19 23:29:45 UTC (rev 13598)
@@ -4753,7 +4753,10 @@
       log_warn(LD_BUG, "Unable to parse state in \"%s\". Moving it aside "
                "to \"%s\".  This could be a bug in Tor; please tell "
                "the developers.", fname, fname2);
-      (int)rename(fname, fname2);
+      if (rename(fname, fname2) < 0) {
+        log_warn(LD_BUG, "Weirdly, I couldn't even mode the state aside. The "
+                 "OS gave an error of %s", strerror(errno));
+      }
     }
     tor_free(fname2);
     tor_free(contents);

Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c	2008-02-19 23:14:34 UTC (rev 13597)
+++ tor/trunk/src/or/routerparse.c	2008-02-19 23:29:45 UTC (rev 13598)
@@ -1126,13 +1126,15 @@
   router->cache_info.signed_descriptor_len = end-s;
   if (cache_copy) {
     size_t len = router->cache_info.signed_descriptor_len +
-                router->cache_info.annotations_len;
+                 router->cache_info.annotations_len;
     char *cp =
       router->cache_info.signed_descriptor_body = tor_malloc(len+1);
     if (prepend_annotations) {
       memcpy(cp, prepend_annotations, prepend_len);
       cp += prepend_len;
     }
+    tor_assert(cp+(end-start_of_annotations) ==
+               router->cache_info.signed_descriptor_body+len);
     memcpy(cp, start_of_annotations, end-start_of_annotations);
     router->cache_info.signed_descriptor_body[len] = '\0';
     tor_assert(strlen(router->cache_info.signed_descriptor_body) == len);