From fd2603247df24c5b35c496a3a2f5d7ad2e052334 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Wed, 10 May 2017 20:01:23 +0200 Subject: [PATCH] Fix onionbindip for some systems with IPv6 - in some cases when IPv6 stack is available and onionbindip is an IPv4 address, socket.bind doesn't change the bound address, ending up listening on everything --- src/class_singleListener.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/class_singleListener.py b/src/class_singleListener.py index 243a494a..7626542d 100644 --- a/src/class_singleListener.py +++ b/src/class_singleListener.py @@ -33,6 +33,10 @@ class singleListener(threading.Thread, StoppableThread): HOST = '' # Symbolic name meaning all available interfaces # If not sockslisten, but onionhostname defined, only listen on localhost if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'sockslisten') and ".onion" in BMConfigParser().get('bitmessagesettings', 'onionhostname'): + if family == socket.AF_INET6 and "." in BMConfigParser().get('bitmessagesettings', 'onionbindip'): + raise socket.error(errno.EINVAL, "Invalid mix of IPv4 and IPv6") + elif family == socket.AF_INET and ":" in BMConfigParser().get('bitmessagesettings', 'onionbindip'): + raise socket.error(errno.EINVAL, "Invalid mix of IPv4 and IPv6") HOST = BMConfigParser().get('bitmessagesettings', 'onionbindip') PORT = BMConfigParser().getint('bitmessagesettings', 'port') sock = socket.socket(family, socket.SOCK_STREAM)