[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/master] Stop parsing immediately if there is an invalid port in an addr.PortList.



commit dd6eea76b85d7f71f108ea3cc55df0638521655e
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Sat Dec 7 04:41:07 2013 +0000

    Stop parsing immediately if there is an invalid port in an addr.PortList.
    
    This ensures that an addr.InvalidPort exception is raised when an invalid port
    is discovered, without continuing to parse the rest of the ports. The end
    result, i.e. when/if an exception is raised, stays exactly the same. This just
    operates more efficiently when there is a bad port number.
---
 lib/bridgedb/parse/addr.py |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/bridgedb/parse/addr.py b/lib/bridgedb/parse/addr.py
index 3d8c9b9..ed00925 100644
--- a/lib/bridgedb/parse/addr.py
+++ b/lib/bridgedb/parse/addr.py
@@ -331,9 +331,9 @@ class PortList(object):
                 if isinstance(arg, basestring):
                     ports = set([int(p)
                                  for p in arg.split(',')][:self.PORTSPEC_LEN])
-                    portlist.extend([p for p in ports])
+                    portlist.extend([self._sanitycheck(p) for p in ports])
                 if isinstance(arg, int):
-                    portlist.extend(arg)
+                    portlist.append(self._sanitycheck(arg))
                 if isinstance(arg, PortList):
                     self.add(list(arg.ports))
             except ValueError:
@@ -341,7 +341,6 @@ class PortList(object):
             except InvalidPort:
                 raise
 
-            [self._sanitycheck(port) for port in portlist]
             self.ports.update(portlist)
 
     def __iter__(self):



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits