]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Check for empty smartlists and no bandwidth during node selection.
authorMike Perry <mikeperry-git@fscked.org>
Sat, 27 Feb 2010 00:17:09 +0000 (16:17 -0800)
committerMike Perry <mikeperry-git@fscked.org>
Sat, 27 Feb 2010 00:17:09 +0000 (16:17 -0800)
src/or/routerlist.c

index 80229f21417d1ff9143bd223fb10e710408d8a84..4daf1e6abdefaba7aad8323c2cf130d2cb945fe1 100644 (file)
@@ -1576,6 +1576,13 @@ smartlist_choose_by_bandwidth_weights(smartlist_t *sl,
              rule == WEIGHT_FOR_MID ||
              rule == WEIGHT_FOR_DIR);
 
+  if (!sl || smartlist_len(sl) == 0) {
+    log_warn(LD_CIRC,
+             "Empty routerlist passed in to node selection for rule %d",
+             rule);
+    return NULL;
+  }
+
   weight_scale = networkstatus_get_param(NULL, "bwweightscale",
                                          BW_WEIGHT_SCALE);
 
@@ -1694,6 +1701,15 @@ smartlist_choose_by_bandwidth_weights(smartlist_t *sl,
             "Wg=%lf Wm=%lf We=%lf Wd=%lf with total bw %lf", rule,
             Wg, Wm, We, Wd, weighted_bw);
 
+  /* If there is no bandwidth, choose at random */
+  if (DBL_TO_U64(weighted_bw) == 0) {
+    log_warn(LD_CIRC,
+             "Weighted bandwidth is %lf in node selection for rule %d",
+             weighted_bw, rule);
+    tor_free(bandwidths);
+    return smartlist_choose(sl);
+  }
+
   rand_bw = crypto_rand_uint64(DBL_TO_U64(weighted_bw));
   rand_bw++; /* crypto_rand_uint64() counts from 0, and we need to count
               * from 1 below. See bug 1203 for details. */
@@ -1767,6 +1783,13 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule,
              rule == WEIGHT_FOR_EXIT ||
              rule == WEIGHT_FOR_GUARD);
 
+  if (!sl || smartlist_len(sl) == 0) {
+    log_warn(LD_CIRC,
+             "Empty routerlist passed in to node selection for rule %d",
+             rule);
+    return NULL;
+  }
+
   /* First count the total bandwidth weight, and make a list
    * of each value.  <0 means "unknown; no routerinfo."  We use the
    * bits of negative values to remember whether the router was fast (-x)&1