From f5eed4c809cc898188896841ce1edae70918c739 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 24 Apr 2011 22:15:20 -0400 Subject: [PATCH] Don't try to connect to remote IPs that start with zero. For some reason, on Linux servers this returns EINVAL. I don't like just treating EINVAL as non-fatal in general, so let's catch this specific case and ignore it. Reported by Reza Mohammadi on the mailing list. Interestingly, it's kind of hard to trigger this crash since the client would have to request the connection, and that connection shouldn't exist because the original client program would have already gotten EINVAL. But my MacOS machine can generate such a connection, so a MacOS->Linux sshuttle could trigger this. --- ssnet.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ssnet.py b/ssnet.py index 2abf5d0..a987562 100644 --- a/ssnet.py +++ b/ssnet.py @@ -124,6 +124,12 @@ class SockWrapper: return # already connected self.rsock.setblocking(False) debug3('%r: trying connect to %r\n' % (self, self.connect_to)) + if socket.inet_aton(self.connect_to[0])[0] == '\0': + self.seterr(Exception("Can't connect to %r: " + "IP address starts with zero\n" + % (self.connect_to,))) + self.connect_to = None + return try: self.rsock.connect(self.connect_to) # connected successfully (Linux)