[tor-commits] [stem/master] Only first 'transport' line was being used

atagar at torproject.org atagar at torproject.org
Sun Mar 3 23:16:37 UTC 2013


commit 954bced4f16b05bd6a4923cfe3a8297f0e3347a6
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Mar 3 15:08:01 2013 -0800

    Only first 'transport' line was being used
    
    The extrainfo descriptor parser only utilized the first 'transport' line,
    causing further lines to be ignored. Caught by asn.
---
 stem/descriptor/extrainfo_descriptor.py      |   67 +++++++++++++-------------
 test/unit/descriptor/extrainfo_descriptor.py |    5 ++
 2 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index dce95a5..9b0ffa3 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -480,41 +480,42 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
         # on non-bridges in the wild when the relay operator configured it this
         # way.
 
-        name, address, port, args = None, None, None, None
+        for transport_value, _ in values:
+          name, address, port, args = None, None, None, None
 
-        if not ' ' in value:
-          # scrubbed
-          name = value
-        else:
-          # not scrubbed
-          value_comp = value.split()
-
-          if len(value_comp) < 1:
-            raise ValueError("Transport line is missing its transport name: %s" % line)
-          else:
-            name = value_comp[0]
-
-          if len(value_comp) < 2:
-            raise ValueError("Transport line is missing its address:port value: %s" % line)
-          elif not ":" in value_comp[1]:
-            raise ValueError("Transport line's address:port entry is missing a colon: %s" % line)
-          else:
-            address, port_str = value_comp[1].split(':', 1)
-
-            if not stem.util.connection.is_valid_ip_address(address) or \
-                   stem.util.connection.is_valid_ipv6_address(address):
-              raise ValueError("Transport line has a malformed address: %s" % line)
-            elif not stem.util.connection.is_valid_port(port_str):
-              raise ValueError("Transport line has a malformed port: %s" % line)
-
-            port = int(port_str)
-
-          if len(value_comp) >= 3:
-            args = value_comp[2:]
+          if not ' ' in transport_value:
+            # scrubbed
+            name = transport_value
           else:
-            args = []
-
-        self.transport[name] = (address, port, args)
+            # not scrubbed
+            value_comp = transport_value.split()
+
+            if len(value_comp) < 1:
+              raise ValueError("Transport line is missing its transport name: %s" % line)
+            else:
+              name = value_comp[0]
+
+            if len(value_comp) < 2:
+              raise ValueError("Transport line is missing its address:port value: %s" % line)
+            elif not ":" in value_comp[1]:
+              raise ValueError("Transport line's address:port entry is missing a colon: %s" % line)
+            else:
+              address, port_str = value_comp[1].split(':', 1)
+
+              if not stem.util.connection.is_valid_ip_address(address) or \
+                     stem.util.connection.is_valid_ipv6_address(address):
+                raise ValueError("Transport line has a malformed address: %s" % line)
+              elif not stem.util.connection.is_valid_port(port_str):
+                raise ValueError("Transport line has a malformed port: %s" % line)
+
+              port = int(port_str)
+
+            if len(value_comp) >= 3:
+              args = value_comp[2:]
+            else:
+              args = []
+
+          self.transport[name] = (address, port, args)
       elif keyword == "cell-circuits-per-decile":
         # "cell-circuits-per-decile" num
 
diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py
index e83a2b1..6a2dd34 100644
--- a/test/unit/descriptor/extrainfo_descriptor.py
+++ b/test/unit/descriptor/extrainfo_descriptor.py
@@ -487,6 +487,11 @@ class TestExtraInfoDescriptor(unittest.TestCase):
     self.assertEquals({"obfs2": ("83.212.96.201", 33570, [])}, desc.transport)
     self.assertEquals([], desc.get_unrecognized_lines())
 
+    # multiple transport lines
+    desc = get_bridge_extrainfo_descriptor({"transport": "obfs3\ntransport obfs4"})
+    self.assertEquals({"obfs3": (None, None, None), "obfs4": (None, None, None)}, desc.transport)
+    self.assertEquals([], desc.get_unrecognized_lines())
+
   def _expect_invalid_attr(self, desc_text, attr = None, expected_value = None):
     """
     Asserts that construction will fail due to desc_text having a malformed



More information about the tor-commits mailing list