Hi,
SELECT '192.168.0.0/4294967320'::inet; -- 2^32 + 24, accepted as
192.168.0.0/24
SELECT '10.0.0.0/4294967304'::cidr; -- 2^32 + 8, accepted as 10.0.0.0/8
Both should fail. These do:
SELECT '192.168.0.0/33'::inet; -- ERROR, 33 > 32
SELECT '192.168.0.0/2494967320'::inet; -- ERROR, wraps negative
SELECT '::1/4294967320'::inet; -- ERROR, IPv6 checks
inside the loop
There is a check, but it runs after the digit loop and tests the wrapped
value, i.e. the prefix length mod 2^32. Any input whose residue lands in
0..32 is accepted:
SELECT '192.168.0.0/4294967296'::inet; -- 2^32 + 0, accepted as
192.168.0.0/0
SELECT '192.168.0.0/4294967314'::inet; -- 2^32 + 18, accepted as
192.168.0.0/18
The attached patch moves the check into the digit loop.
Regards,
Iliia
0001-Reject-IPv4-prefix-lengths-that-overflow-int.patch
Description: Binary data
