[tor-commits] [sbws/master] fix: relaylist: catch exception accessing exit_policy

juga at torproject.org juga at torproject.org
Wed Mar 27 09:59:23 UTC 2019


commit 32f283f75965bde77ff2b3e6208b8a9f106e7708
Author: juga0 <juga at riseup.net>
Date:   Tue Mar 26 09:24:42 2019 +0000

    fix: relaylist: catch exception accessing exit_policy
---
 sbws/lib/relaylist.py | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index febc717..289e0d2 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -228,9 +228,23 @@ class Relay:
         """
         assert isinstance(port, int)
         # if dind't get the descriptor, there isn't exit policy
-        if not self.exit_policy:
+        # When the attribute is gotten in getattr(self._desc, "exit_policy"),
+        # is possible that stem's _input_rules is None and raises an exception
+        # (#29899):
+        #   File "/usr/lib/python3/dist-packages/sbws/lib/relaylist.py", line 117, in can_exit_to_port  # noqa
+        #     if not self.exit_policy:
+        #   File "/usr/lib/python3/dist-packages/stem/exit_policy.py", line 512, in __len__  # noqa
+        #     return len(self._get_rules())
+        #   File "/usr/lib/python3/dist-packages/stem/exit_policy.py", line 464, in _get_rules  # noqa
+        #     for rule in decompressed_rules:
+        # TypeError: 'NoneType' object is not iterable
+        # Therefore, catch the exception here.
+        try:
+            if self.exit_policy:
+                return self.exit_policy.can_exit_to(port=port)
+        except TypeError:
             return False
-        return self.exit_policy.can_exit_to(port=port)
+        return False
 
     def is_exit_not_bad_allowing_port(self, port):
         return (Flag.BADEXIT not in self.flags and





More information about the tor-commits mailing list