summaryrefslogtreecommitdiff
path: root/src/or/networkstatus.c
diff options
context:
space:
mode:
authorSebastian Hahn <sebastian@torproject.org>2011-01-15 19:31:23 +0100
committerSebastian Hahn <sebastian@torproject.org>2011-01-15 19:42:17 +0100
commitb06617c9481ff577e2f0fed4264c80a718f98c29 (patch)
tree5c1b8481446be7a50821da08495606e45386a07a /src/or/networkstatus.c
parent932e5c3cf0bd890313b035a4ab00003e81adb720 (diff)
downloadtor-b06617c9481ff577e2f0fed4264c80a718f98c29.tar.gz
tor-b06617c9481ff577e2f0fed4264c80a718f98c29.zip
Provide constant limits for all consensus params
This addresses Nick's concern about doing non-constant bounds checking inside networkstatus_get_param().
Diffstat (limited to 'src/or/networkstatus.c')
-rw-r--r--src/or/networkstatus.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 50bb88bb96..687ac03fa0 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -2190,15 +2190,24 @@ int32_t
networkstatus_get_bw_weight(networkstatus_t *ns, const char *weight_name,
int32_t default_val)
{
+ int32_t param;
+ int max;
if (!ns) /* if they pass in null, go find it ourselves */
ns = networkstatus_get_latest_consensus();
if (!ns || !ns->weight_params)
return default_val;
- return get_net_param_from_list(ns->weight_params, weight_name,
- default_val, -1,
- circuit_build_times_get_bw_scale(ns));
+ max = circuit_build_times_get_bw_scale(ns);
+ param = get_net_param_from_list(ns->weight_params, weight_name,
+ default_val, -1,
+ BW_MAX_WEIGHT_SCALE);
+ if (param > max) {
+ log_warn(LD_DIR, "Value of consensus weight %s was too large, capping "
+ "to %d", weight_name, max);
+ param = max;
+ }
+ return param;
}
/** Return the name of the consensus flavor <b>flav</b> as used to identify