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

[tor-commits] [stem/master] Validate address before connecting



commit 801ceb20f5cb113253d88956fac9a9501ce2521e
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Feb 7 12:27:43 2018 -0800

    Validate address before connecting
    
    Oops, the Address constructor indeed validates addresses *but* it was called
    after we established a socket. As such our integ tests failed with...
    
      ======================================================================
      ERROR: test_invalid_arguments
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "/srv/jenkins-workspace/workspace/stem-tor-ci/test/integ/client/connection.py", line 20, in test_invalid_arguments
          self.assertRaisesRegexp(ValueError, "'nope' isn't an IPv4 or IPv6 address", Relay.connect, 'nope', 80)
        File "/srv/jenkins-workspace/workspace/stem-tor-ci/stem/util/test_tools.py", line 278, in assertRaisesRegexp
          return super(original_type, self).assertRaisesRegexp(exc_type, exc_msg, func, *args, **kwargs)
        File "/usr/lib/python2.7/unittest/case.py", line 993, in assertRaisesRegexp
          callable_obj(*args, **kwargs)
        File "/srv/jenkins-workspace/workspace/stem-tor-ci/stem/client/__init__.py", line 80, in connect
          conn = stem.socket.RelaySocket(address, port)
        File "/srv/jenkins-workspace/workspace/stem-tor-ci/stem/socket.py", line 378, in __init__
          self.connect()
        File "/srv/jenkins-workspace/workspace/stem-tor-ci/stem/socket.py", line 177, in connect
          self._socket = self._make_socket()
        File "/srv/jenkins-workspace/workspace/stem-tor-ci/stem/socket.py", line 418, in _make_socket
          raise stem.SocketError(exc)
      SocketError: [Errno -2] Name or service not known
    
      ----------------------------------------------------------------------
---
 stem/client/__init__.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/stem/client/__init__.py b/stem/client/__init__.py
index 2b853baa..340082c7 100644
--- a/stem/client/__init__.py
+++ b/stem/client/__init__.py
@@ -71,6 +71,8 @@ class Relay(object):
       * :class:`stem.SocketError` if we're unable to establish a connection
     """
 
+    relay_addr = Address(address)
+
     if not stem.util.connection.is_valid_port(port):
       raise ValueError("'%s' isn't a valid port" % port)
     elif not link_protocols:
@@ -108,7 +110,7 @@ class Relay(object):
     # where it would help.
 
     link_protocol = max(common_protocols)
-    conn.send(stem.client.cell.NetinfoCell(Address(address), []).pack(link_protocol))
+    conn.send(stem.client.cell.NetinfoCell(relay_addr, []).pack(link_protocol))
 
     return Relay(conn, link_protocol)
 

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