[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [pytorctl/master 2/2] Fix IP address regular expression in ExitPolicyLine.__init__
Author: Harry Bock <hbock@xxxxxxxxxxx>
Date: Sat, 29 May 2010 00:23:40 -0400
Subject: Fix IP address regular expression in ExitPolicyLine.__init__
Commit: 12f8114c00fa3e461b773ee2434f434955c3bd14
Previous expression "\d+.\d+.\d+.\d+" matches many many things which are
probably not intended. Use "(\d{1,3}\.){3}\d{1,3}$" instead and compile it for
efficiency.
---
TorCtl.py | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/TorCtl.py b/TorCtl.py
index d6307ce..3e3a034 100755
--- a/TorCtl.py
+++ b/TorCtl.py
@@ -231,6 +231,7 @@ class UnknownEvent(Event):
Event.__init__(self, event_name)
self.event_string = event_string
+ipaddress_re = re.compile(r"(\d{1,3}\.){3}\d{1,3}$")
class ExitPolicyLine:
""" Class to represent a line in a Router's exit policy in a way
that can be easily checked. """
@@ -245,7 +246,7 @@ class ExitPolicyLine:
ip = ip_mask
else:
ip, mask = ip_mask.split("/")
- if re.match(r"\d+.\d+.\d+.\d+", mask):
+ if ipaddress_re.match(mask):
self.netmask=struct.unpack(">I", socket.inet_aton(mask))[0]
else:
self.netmask = 0xffffffff ^ (0xffffffff >> int(mask))
--
1.6.5