commit ea4964267e519c33b039f88d9d857a8f6452b3a3 Author: Damian Johnson atagar@torproject.org Date: Sun Jan 20 23:55:05 2013 -0800
Empty bridge-ip-versions value broke parser
A 'bridge-ip-versions' line without a value broke our parser...
File "/home/karsten/tasks/task-7828/stem/stem/descriptor/extrainfo_descriptor.py", line 858, in __init__ super(BridgeExtraInfoDescriptor, self).__init__(raw_contents, validate) File "/home/karsten/tasks/task-7828/stem/stem/descriptor/extrainfo_descriptor.py", line 413, in __init__ self._parse(entries, validate) File "/home/karsten/tasks/task-7828/stem/stem/descriptor/extrainfo_descriptor.py", line 882, in _parse raise stem.ProtocolError("The bridge-ip-versions should be a comma separated listing of '<protocol>=<count>' mappings: '%s' (entry = '%s')" % (line, entry, )) ProtocolError: The bridge-ip-versions should be a comma separated listing of '<protocol>=<count>' mappings: 'bridge-ip-versions ' (entry = '')
Reported by Karsten on...
https://trac.torproject.org/7967 --- stem/descriptor/extrainfo_descriptor.py | 15 ++++++++------- test/unit/descriptor/extrainfo_descriptor.py | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py index 75e974e..9d39f92 100644 --- a/stem/descriptor/extrainfo_descriptor.py +++ b/stem/descriptor/extrainfo_descriptor.py @@ -880,16 +880,17 @@ class BridgeExtraInfoDescriptor(ExtraInfoDescriptor): elif keyword == "bridge-ip-versions": self.ip_versions = {}
- for entry in value.split(','): - if not '=' in entry: - raise stem.ProtocolError("The bridge-ip-versions should be a comma separated listing of '<protocol>=<count>' mappings: %s" % line) + if value: + for entry in value.split(','): + if not '=' in entry: + raise stem.ProtocolError("The bridge-ip-versions should be a comma separated listing of '<protocol>=<count>' mappings: %s" % line)
- protocol, count = entry.split('=', 1) + protocol, count = entry.split('=', 1)
- if not count.isdigit(): - raise stem.ProtocolError("IP protocol count was non-numeric (%s): %s" % (count, line)) + if not count.isdigit(): + raise stem.ProtocolError("IP protocol count was non-numeric (%s): %s" % (count, line))
- self.ip_versions[protocol] = int(count) + self.ip_versions[protocol] = int(count)
del entries["bridge-ip-versions"]
diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py index 524dfab..e83a2b1 100644 --- a/test/unit/descriptor/extrainfo_descriptor.py +++ b/test/unit/descriptor/extrainfo_descriptor.py @@ -468,6 +468,9 @@ class TestExtraInfoDescriptor(unittest.TestCase): desc = get_bridge_extrainfo_descriptor({"bridge-ip-versions": "v4=16,v6=40"}) self.assertEquals({'v4': 16, 'v6': 40}, desc.ip_versions)
+ desc = get_bridge_extrainfo_descriptor({"bridge-ip-versions": ""}) + self.assertEquals({}, desc.ip_versions) + desc_text = get_bridge_extrainfo_descriptor({"bridge-ip-versions": "v4=24.5"}, content = True) self.assertRaises(ValueError, RelayExtraInfoDescriptor, desc_text)
tor-commits@lists.torproject.org