[#2082] Validate ip address for listen_interface entry

This ensures that only ip addresses are accepted for
listen_interface as libtorrent cannot accept interface
names (eth0) and will cause unexpected results for user.
This commit is contained in:
Calum Lind 2014-02-11 16:23:27 +00:00
parent bddfb2a5c6
commit 2be5474f3a
4 changed files with 11 additions and 8 deletions

View File

@ -52,7 +52,7 @@ try:
except ImportError:
import simplejson as json
from deluge.error import *
from deluge.error import InvalidPathError
log = logging.getLogger(__name__)
@ -593,10 +593,10 @@ def is_ip(ip):
#first we test ipv4
try:
if windows_check():
if socket.inet_aton("%s" % (ip)):
if socket.inet_aton(ip):
return True
else:
if socket.inet_pton(socket.AF_INET, "%s" % (ip)):
if socket.inet_pton(socket.AF_INET, ip):
return True
except socket.error:
if not socket.has_ipv6:
@ -607,7 +607,7 @@ def is_ip(ip):
log.warning("ipv6 check unavailable on windows")
return True
else:
if socket.inet_pton(socket.AF_INET6, "%s" % (ip)):
if socket.inet_pton(socket.AF_INET6, ip):
return True
except socket.error:
return False

View File

@ -137,7 +137,7 @@ class Core(component.Component):
# If there was an interface value from the command line, use it, but
# store the one in the config so we can restore it on shutdown
self.__old_interface = None
if listen_interface:
if listen_interface and deluge.common.is_ip(listen_interface):
self.__old_interface = self.config["listen_interface"]
self.config["listen_interface"] = listen_interface

View File

@ -37,7 +37,7 @@ from twisted.internet import reactor
import deluge.component as component
from deluge.configmanager import get_config_dir
from deluge.common import get_version, windows_check
from deluge.common import get_version, windows_check, is_ip
from deluge.core.rpcserver import RPCServer, export
from deluge.error import DaemonRunningError
from deluge.core.core import Core
@ -110,7 +110,7 @@ class Daemon(object):
SetConsoleCtrlHandler(win_handler)
listen_interface = None
if options and options.listen_interface:
if options and options.listen_interface and is_ip(options.listen_interface):
listen_interface = options.listen_interface
# Start the core as a thread and join it until it's done

View File

@ -611,7 +611,10 @@ class Preferences(component.Component):
new_core_config["outgoing_ports"] = outgoing_ports
new_core_config["random_outgoing_ports"] = \
self.builder.get_object("chk_random_outgoing_ports").get_active()
new_core_config["listen_interface"] = self.builder.get_object("entry_interface").get_text()
incoming_address = self.builder.get_object("entry_interface").get_text()
if deluge.common.is_ip(incoming_address) or not incoming_address:
new_core_config["listen_interface"] = incoming_address
new_core_config["peer_tos"] = self.builder.get_object("entry_peer_tos").get_text()
new_core_config["dht"] = self.builder.get_object("chk_dht").get_active()
new_core_config["upnp"] = self.builder.get_object("chk_upnp").get_active()