DescriptionThe previous code checks each octet separately, and then checks if
the sequence of octets is nonincreasing. This is insufficient, because
it allows nonsensical inputs like "255.128.128.0".
The previous code also only partially handles hostmasks (inverted netmasks).
"0.255.255.255" becomes /8, but 0.15.255.255 is rejected.
The solution is to disregard octets, and interpret the address as a
single sequence of bits.
Note that this could be trivially extended to support IPv6 netmasks and
hostmasks, but those are non-standard.
I've also made the CIDR parser more strict, so it rejects anything that's
not not a decimal digit, like /+24
Added:
- _prefix_from_prefix_string: Parse a number, with bounds checking.
- _prefix_from_ip_string: Parse IPv4 netmask/hostmask string.
Improved:
- _prefix_from_ip_int: Only accept inputs with the bit sequence /1*0*/.
Removed:
- _ip_string_from_prefix
- _is_hostmask
- _is_valid_netmask
Patch Set 1 #
Total comments: 6
Patch Set 2 : Tweak comments #
MessagesTotal messages: 7
|