]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Detect insanely large circuit build state; don't give its length to rand_int
authorNick Mathewson <nickm@torproject.org>
Wed, 1 Jun 2011 16:12:01 +0000 (12:12 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 6 Jun 2011 20:18:06 +0000 (16:18 -0400)
changes/bug3306
src/or/circuitbuild.c

index b1bb1035cf7d531ceb5ca8a785b9c3fa97cedcc1..f868a24af05bed83929c9ad7db43a1ed1ed1ea47 100644 (file)
@@ -3,3 +3,7 @@
       correctly. Previously, it accepted values up to UINT_MAX, but
       could return a negative number if given a value above INT_MAX+1.
       Found by George Kadianakis. Fixes bug 3306; bugfix on 0.2.2pre14.
+
+    - Avoid a segfault when reading a malformed circuit build state
+      with more than INT_MAX entries. Found by wanoskarnet. Bugfix on
+      0.2.2.4-alpha.
index 3f084481597440764c585be7ad8789b92c041fff..6d7e71194ec4ddc7d4dcb0091b0ec7c7c62cec65 100644 (file)
@@ -678,7 +678,15 @@ circuit_build_times_shuffle_and_store_array(circuit_build_times_t *cbt,
     log_notice(LD_CIRC, "The number of circuit times that this Tor version "
                "uses to calculate build times is less than the number stored "
                "in your state file. Decreasing the circuit time history from "
-               "%d to %d.", num_times, CBT_NCIRCUITS_TO_OBSERVE);
+               "%lu to %d.", (unsigned long)num_times,
+               CBT_NCIRCUITS_TO_OBSERVE);
+  }
+
+  if (n > INT_MAX-1) {
+    log_warn(LD_CIRC, "For some insane reasons, you had %lu circuit build "
+             "observations in your state file. That's far too many; probably "
+             "there's a bug here.", (unsigned long)n);
+    n = INT_MAX-1;
   }
 
   /* This code can only be run on a compact array */