[tor-commits] [tor/master] Don't pass invalid memory regions to digestmap_set/get in test_routerlist

nickm at torproject.org nickm at torproject.org
Mon Sep 15 18:05:15 UTC 2014


commit 0bd220adcb82670893c85b1cc24d64e615855b4f
Author: Nick Mathewson <nickm at torproject.org>
Date:   Mon Sep 15 14:04:19 2014 -0400

    Don't pass invalid memory regions to digestmap_set/get in test_routerlist
    
    Fixes bug in c887e20e6a5a2c17c65; bug in no released Tor version.
---
 src/test/test_routerset.c |   14 +++++++++-----
 src/test/test_util.c      |   36 +++++++++++++++---------------------
 2 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/src/test/test_routerset.c b/src/test/test_routerset.c
index 0ea1ef2..81e4dbb 100644
--- a/src/test/test_routerset.c
+++ b/src/test/test_routerset.c
@@ -775,10 +775,11 @@ NS(test_main)(void *arg)
 {
   routerset_t *set = routerset_new();
   int contains;
+  uint8_t foo[20] = { 2, 3, 4 };
   (void)arg;
 
-  digestmap_set(set->digests, "foo", (void *)1);
-  contains = routerset_contains(set, NULL, 0, NULL, "foo", 0);
+  digestmap_set(set->digests, (const char*)foo, (void *)1);
+  contains = routerset_contains(set, NULL, 0, NULL, (const char*)foo, 0);
   routerset_free(set);
 
   tt_int_op(contains, ==, 4);
@@ -799,10 +800,12 @@ NS(test_main)(void *arg)
 {
   routerset_t *set = routerset_new();
   int contains;
+  uint8_t bar[20] = { 9, 10, 11, 55 };
+  uint8_t foo[20] = { 1, 2, 3, 4};
   (void)arg;
 
-  digestmap_set(set->digests, "bar", (void *)1);
-  contains = routerset_contains(set, NULL, 0, NULL, "foo", 0);
+  digestmap_set(set->digests, (const char*)bar, (void *)1);
+  contains = routerset_contains(set, NULL, 0, NULL, (const char*)foo, 0);
   routerset_free(set);
 
   tt_int_op(contains, ==, 0);
@@ -823,9 +826,10 @@ NS(test_main)(void *arg)
 {
   routerset_t *set = routerset_new();
   int contains;
+  uint8_t bar[20] = { 9, 10, 11, 55 };
   (void)arg;
 
-  digestmap_set(set->digests, "bar", (void *)1);
+  digestmap_set(set->digests, (const char*)bar, (void *)1);
   contains = routerset_contains(set, NULL, 0, NULL, NULL, 0);
   routerset_free(set);
 
diff --git a/src/test/test_util.c b/src/test/test_util.c
index d195003..962cb0e 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -3362,30 +3362,24 @@ test_util_di_ops(void)
     test_eq(neq1, !eq1);
   }
 
-  /* exhaustively white-box test tor_memeq
-   * against each possible (single-byte) bit difference
-   * some arithmetic bugs only appear with certain bit patterns */
   {
-  uint8_t zz = 0;
-  uint8_t ii = 0;
-  int z;
-  for (i = 0; i < 256; i++) {
-    ii = (uint8_t)i;
-    test_eq(tor_memeq(&zz, &ii, 1), zz == ii);
-  }
-
-  /* exhaustively white-box test tor_memcmp
-   * against each possible single-byte numeric difference
-   * some arithmetic bugs only appear with certain bit patterns */
-  for (z = 0; z < 256; z++) {
-    for (i = 0; i < 256; i++) {
-      ii = (uint8_t)i;
-      zz = (uint8_t)z;
-      test_eq(tor_memcmp(&zz, &ii, 1) > 0 ? GT : EQ, zz > ii ? GT : EQ);
-      test_eq(tor_memcmp(&ii, &zz, 1) < 0 ? LT : EQ, ii < zz ? LT : EQ);
+    uint8_t zz = 0;
+    uint8_t ii = 0;
+    int z;
+
+    /* exhaustively test tor_memeq and tor_memcmp
+     * against each possible single-byte numeric difference
+     * some arithmetic bugs only appear with certain bit patterns */
+    for (z = 0; z < 256; z++) {
+      for (i = 0; i < 256; i++) {
+        ii = (uint8_t)i;
+        zz = (uint8_t)z;
+        test_eq(tor_memeq(&zz, &ii, 1), zz == ii);
+        test_eq(tor_memcmp(&zz, &ii, 1) > 0 ? GT : EQ, zz > ii ? GT : EQ);
+        test_eq(tor_memcmp(&ii, &zz, 1) < 0 ? LT : EQ, ii < zz ? LT : EQ);
+      }
     }
   }
-  }
 
   tt_int_op(1, ==, safe_mem_is_zero("", 0));
   tt_int_op(1, ==, safe_mem_is_zero("", 1));



More information about the tor-commits mailing list