summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvery Pennarun <apenwarr@gmail.com>2011-04-24 22:15:20 -0400
committerAvery Pennarun <apenwarr@gmail.com>2011-04-24 22:15:20 -0400
commitf5eed4c809cc898188896841ce1edae70918c739 (patch)
tree17ec5306775504c388362d99eeb91e95397c9b2e
parent783d33cada4bbb7282877330abd7b16c7e2ab1fe (diff)
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.
-rw-r--r--ssnet.py6
1 files changed, 6 insertions, 0 deletions
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)