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

[tor-commits] [pytorctl/master] Handling for connections to non-control sockets



commit e76418e507319887626b9d3921bdc0ac44b28e76
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Jun 13 09:50:13 2011 -0700

    Handling for connections to non-control sockets
    
    When we attempt to initiate a control connection to a non-control port (for
    instance tor's socks port instead)...
    - the socket shutdown issues an error since it's not connected yet
    - checking the authentication type fails with a TorCtlClosed rather than error
      reply
    
    For more information see bug 2580.
---
 TorCtl.py  |    5 +++--
 TorUtil.py |    7 ++++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/TorCtl.py b/TorCtl.py
index 056a65c..44a612b 100755
--- a/TorCtl.py
+++ b/TorCtl.py
@@ -590,8 +590,9 @@ class Connection:
       # check PROTOCOLINFO for authentication type
       try:
         authInfo = self.sendAndRecv("PROTOCOLINFO\r\n")[1][1]
-      except ErrorReply, exc:
-        raise IOError("Unable to query PROTOCOLINFO for the authentication type: %s" % exc)
+      except Exception, exc:
+        excMsg = ": %s" % exc if exc.message else ""
+        raise IOError("Unable to query PROTOCOLINFO for the authentication type%s" % excMsg)
       
       authType, cookiePath = None, None
       if authInfo.startswith("AUTH METHODS=NULL"):
diff --git a/TorUtil.py b/TorUtil.py
index 29c44bf..fcbef70 100644
--- a/TorUtil.py
+++ b/TorUtil.py
@@ -231,7 +231,12 @@ class BufSock:
 
   def close(self):
     self._isDone = True
-    self._s.shutdown(socket.SHUT_RDWR)
+
+    # if we haven't yet established a connection then this raises an error
+    # socket.error: [Errno 107] Transport endpoint is not connected
+    try: self._s.shutdown(socket.SHUT_RDWR)
+    except socket.error: pass
+
     self._s.close()
 
 # SocketServer.TCPServer is nuts.. 



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