commit d68f8e2427a5b9623a7d4907c177bf2cc46da9b2 Author: Isis Lovecruft isis@torproject.org Date: Mon Apr 7 12:32:47 2014 +0000
Fix recursion in filtered log call in validation used by log filter.
We can't log an IP address in a IP validation function which is used by a log filter in `bridgedb.safelog`, because the log call made in the validation function `bridgedb.parse.addr._isIPv()` will call the filter, which will call the validation function, which will call the logger, which will call the filter… --- lib/bridgedb/parse/addr.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/lib/bridgedb/parse/addr.py b/lib/bridgedb/parse/addr.py index 927de2f..455b953 100644 --- a/lib/bridgedb/parse/addr.py +++ b/lib/bridgedb/parse/addr.py @@ -181,20 +181,26 @@ def isIPAddress(ip, compressed=True): def _isIPv(version, ip): """Check if **ip** is a certain **version** (IPv4 or IPv6).
+ .. warning: Do *not* put any calls to the logging module in this function, + or else an infinite recursion will occur when the call is made, due + the the log :class:`~logging.Filter`s in :mod:`~bridgedb.safelog` + using this function to validate matches from the regular expression + for IP addresses. + :param integer version: The IPv[4|6] version to check; must be either - ``4`` or ``6``. + ``4`` or ``6``. Any other value will be silently changed to ``4``. :param ip: The IP address to check. May be an any type which :class:`ipaddr.IPAddress` will accept. :rtype: boolean :returns: ``True``, if the address is an IPv4 address. """ try: - ip = ipaddr.IPAddress(ip, version=version) - except ipaddr.AddressValueError: - logging.debug("Address %s seems not to be IPv%d." % (ip, version)) + ipaddr.IPAddress(ip, version=version) + except (ipaddr.AddressValueError, Exception): return False else: return True + return False
def isIPv4(ip): """Check if an address is IPv4.
tor-commits@lists.torproject.org