Browse Source

r11981@catbus: nickm | 2007-02-28 11:55:27 -0500
Clamp declarable bandwidth at INT32_MAX, not INT_MAX.


svn:r9677

Nick Mathewson 18 years ago
parent
commit
dae5fc7982
5 changed files with 17 additions and 6 deletions
  1. 2 0
      ChangeLog
  2. 3 0
      src/common/torint.h
  3. 4 4
      src/or/config.c
  4. 1 0
      src/or/or.h
  5. 7 2
      src/or/router.c

+ 2 - 0
ChangeLog

@@ -10,6 +10,8 @@ Changes in version 0.1.2.9-??? - 2007-??-??
   o Minor bugfixes (other):
     - Fix an assert that could trigger if a controller quickly set then
       cleared EntryNodes.  (Bug found by Udo van den Heuvel.)
+    - On architectures where sizeof(int)>4, still clamp declarable bandwidth
+      to INT32_MAX.
 
 
 Changes in version 0.1.2.8-beta - 2007-02-26

+ 3 - 0
src/common/torint.h

@@ -120,6 +120,9 @@ typedef unsigned int uint32_t;
 #ifndef UINT32_MAX
 #define UINT32_MAX 0xffffffffu
 #endif
+#ifndef INT32_MAX
+#define INT32_MAX 0x7fffffffu
+#endif
 #endif
 
 #if (SIZEOF_LONG == 4)

+ 4 - 4
src/or/config.c

@@ -2635,15 +2635,15 @@ options_validate(or_options_t *old_options, or_options_t *options,
   if (options->KeepalivePeriod < 1)
     REJECT("KeepalivePeriod option must be positive.");
 
-  if (options->BandwidthRate > INT_MAX) {
+  if (options->BandwidthRate > ROUTER_MAX_DECLARED_BANDWIDTH) {
     r = tor_snprintf(buf, sizeof(buf),
-                     "BandwidthRate must be less than %d",INT_MAX);
+                     "BandwidthRate must be less than %d",INT32_MAX);
     *msg = tor_strdup(r >= 0 ? buf : "internal error");
     return -1;
   }
-  if (options->BandwidthBurst > INT_MAX) {
+  if (options->BandwidthBurst > ROUTER_MAX_DECLARED_BANDWIDTH) {
     r = tor_snprintf(buf, sizeof(buf),
-                     "BandwidthBurst must be less than %d",INT_MAX);
+                     "BandwidthBurst must be less than %d",INT32_MAX);
     *msg = tor_strdup(r >= 0 ? buf : "internal error");
     return -1;
   }

+ 1 - 0
src/or/or.h

@@ -2903,6 +2903,7 @@ routerinfo_t *router_find_exact_exit_enclave(const char *address,
                                              uint16_t port);
 
 #define ROUTER_REQUIRED_MIN_BANDWIDTH 10000
+#define ROUTER_MAX_DECLARED_BANDWIDTH INT32_MAX
 int router_is_unreliable(routerinfo_t *router, int need_uptime,
                          int need_capacity, int need_guard);
 uint32_t router_get_advertised_bandwidth(routerinfo_t *router);

+ 7 - 2
src/or/router.c

@@ -877,8 +877,13 @@ router_rebuild_descriptor(int force)
   ri->bandwidthburst = (int)options->BandwidthBurst;
   ri->bandwidthcapacity = hibernating ? 0 : rep_hist_bandwidth_assess();
 
-  if (options->BandwidthRate > options->MaxAdvertisedBandwidth)
-    ri->bandwidthrate = (int)options->MaxAdvertisedBandwidth;
+  if (options->BandwidthRate > options->MaxAdvertisedBandwidth) {
+    if (options->MaxAdvertisedBandwidth > ROUTER_MAX_DECLARED_BANDWIDTH) {
+      ri->bandwidthrate = ROUTER_MAX_DECLARED_BANDWIDTH;
+    } else {
+      ri->bandwidthrate = (int)options->MaxAdvertisedBandwidth;
+    }
+  }
 
   policies_parse_exit_policy(options->ExitPolicy, &ri->exit_policy,
                              options->ExitPolicyRejectPrivate);