From: Mark Wooding Date: Thu, 28 Sep 2017 18:10:34 +0000 (+0100) Subject: svc/conntrack.in: Fix netmask parsing. X-Git-Tag: 1.5.0~41^2~15 X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/commitdiff_plain/508294eabafbbf8d898ac2a94fa05262ad244dcf svc/conntrack.in: Fix netmask parsing. * Improve the checking for a prefix length: see if the thing is entirely made of digits, rather than searching for a `.'. * More importantly, if we have a general netmask, then parse the correct part of the network spec as the mask. --- diff --git a/svc/conntrack.in b/svc/conntrack.in index 79b47d88..1b9f5819 100644 --- a/svc/conntrack.in +++ b/svc/conntrack.in @@ -171,11 +171,11 @@ class Config (object): ## a mask with N leading ones followed by trailing zeroes. slash = net.index('/') addr, = unpack('>L', S.inet_aton(net[:slash])) - if net.find('.', slash + 1) >= 0: - mask, = unpack('>L', S.inet_aton(net[:slash])) - else: + if net[slash + 1:].isdigit(): n = int(net[slash + 1:], 10) mask = (1 << 32) - (1 << 32 - n) + else: + mask, = unpack('>L', S.inet_aton(net[slash + 1:])) pats.append((tag, peer, addr & mask, mask)) ## Annoyingly, RawConfigParser doesn't preserve the order of options.