Browse Source

Never process empty string and prevent infinite loop

If user provide an empty string as network range, inet_pton will
treate it as an IPv6 unspecified address, it seems a bug but I
can't confirm. Then empty string will be converted to 0, 0 & 1
always be zero, so it caused dead loop.
master
Sunny 10 years ago
parent
commit
79b9b53dbe
  1. 4
      shadowsocks/common.py

4
shadowsocks/common.py

@ -195,6 +195,8 @@ class IPNetwork(object):
map(self.add_network, addrs)
def add_network(self, addr):
if addr is "":
return
block = addr.split('/')
addr_family = is_ip(block[0])
addr_len = IPNetwork.ADDRLENGTH[addr_family]
@ -207,7 +209,7 @@ class IPNetwork(object):
raise SyntaxError("Not a valid CIDR notation: %s" % addr)
if len(block) is 1:
prefix_size = 0
while ((ip & 1) == 0):
while (ip & 1) == 0 and ip is not 0:
ip >>= 1
prefix_size += 1
logging.warn("You did't specify CIDR routing prefix size for %s, "

Loading…
Cancel
Save