]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
r16462@catbus: nickm | 2007-11-06 14:40:58 -0500
authorNick Mathewson <nickm@torproject.org>
Tue, 6 Nov 2007 19:42:37 +0000 (19:42 +0000)
committerNick Mathewson <nickm@torproject.org>
Tue, 6 Nov 2007 19:42:37 +0000 (19:42 +0000)
 Fix bug 544: do not allow buckets to overflow.  Backportable.

svn:r12400

ChangeLog
src/or/connection.c

index 0f5399fa264fa96d3867eb13d7450230c1457e3a..8e7861c05a859b3a4d1d782435424d6faa410f1d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,8 @@ Changes in version 0.2.0.10-alpha - 2007-11-0?
     - Stop servers from crashing if they set a Family option (or
       maybe in other situations too). Bugfix on 0.2.0.9-alpha; reported
       by Fabian Keil.
+    - When the clock jumps forward a lot, do not allow the bandwidth
+      buckets to become negative.  Bugfix on 0.1.2.x; fixes Bug 544.
 
   o Major bugfixes (v3 dir, bugfixes on 0.2.0.9-alpha):
     - Consider replacing the current consensus when certificates arrive
index daf1e5a7f062688d48a3f2ca28719a59c90a6b22..40aa72d56cb1e6a16f21c4e4560c4d3da5fbcabc 100644 (file)
@@ -1638,14 +1638,20 @@ connection_bucket_init(void)
   }
 }
 
+/** DOCDOC */
 static void
 connection_bucket_refill_helper(int *bucket, int rate, int burst,
                                 int seconds_elapsed, const char *name)
 {
-  if (*bucket < burst) {
-    *bucket += rate*seconds_elapsed;
-    if (*bucket > burst)
+  int starting_bucket = *bucket;
+  if (starting_bucket < burst) {
+    int incr = rate*seconds_elapsed;
+    *bucket += incr;
+    if (*bucket > burst || *bucket < starting_bucket) {
+      /* If we overflow the burst, or underflow our starting bucket,
+       * cap the bucket value to burst. */
       *bucket = burst;
+    }
     log(LOG_DEBUG, LD_NET,"%s now %d.", name, *bucket);
   }
 }