summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Johnson <atagar@torproject.org>2015-05-17 15:18:18 -0700
committerDamian Johnson <atagar@torproject.org>2015-05-17 15:18:18 -0700
commit98d97717486063bb53bb297fde1cb1e9e73d89ff (patch)
treeef687462fc3f2162ef07a3f7f4ed8af79230b4ba
parentcbce47082a9ffb1cab375a6e8307e0eec60775d0 (diff)
Errors when parsing router status entry's 'w' lines
We didn't properly set a default value when parsing 'w' lines, potentially leading to infinite recursion. Caught by Tom on... https://trac.torproject.org/projects/tor/ticket/16048
-rw-r--r--stem/descriptor/router_status_entry.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 561f855c..c33baa39 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -228,6 +228,11 @@ def _parse_w_line(descriptor, entries):
elif not w_comp[0].startswith('Bandwidth='):
raise ValueError("%s 'w' line needs to start with a 'Bandwidth=' entry: w %s" % (descriptor._name(), value))
+ bandwidth = None
+ measured = None
+ is_unmeasured = False
+ unrecognized_bandwidth_entries = []
+
for w_entry in w_comp:
if '=' in w_entry:
w_key, w_value = w_entry.split('=', 1)
@@ -238,19 +243,24 @@ def _parse_w_line(descriptor, entries):
if not (w_value and w_value.isdigit()):
raise ValueError("%s 'Bandwidth=' entry needs to have a numeric value: w %s" % (descriptor._name(), value))
- descriptor.bandwidth = int(w_value)
+ bandwidth = int(w_value)
elif w_key == 'Measured':
if not (w_value and w_value.isdigit()):
raise ValueError("%s 'Measured=' entry needs to have a numeric value: w %s" % (descriptor._name(), value))
- descriptor.measured = int(w_value)
+ measured = int(w_value)
elif w_key == 'Unmeasured':
if w_value != '1':
raise ValueError("%s 'Unmeasured=' should only have the value of '1': w %s" % (descriptor._name(), value))
- descriptor.is_unmeasured = True
+ is_unmeasured = True
else:
- descriptor.unrecognized_bandwidth_entries.append(w_entry)
+ unrecognized_bandwidth_entries.append(w_entry)
+
+ descriptor.bandwidth = bandwidth
+ descriptor.measured = measured
+ descriptor.is_unmeasured = is_unmeasured
+ descriptor.unrecognized_bandwidth_entries = unrecognized_bandwidth_entries
def _parse_p_line(descriptor, entries):