Re: inet/cidr: IPv4 prefix length overflows int and passes the range check

From: Roman Khapov <rkhapov(at)yandex-team(dot)ru>
To: Iliia Khaprov <i(dot)khaprov(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: inet/cidr: IPv4 prefix length overflows int and passes the range check
Date: 2026-10-31 18:08:21
Message-ID: 6BB5B4E1-77B2-4E63-AA59-54732A230DAE@yandex-team.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi!

Moving the check into the digit loop, as
getbits() already does for IPv6, is the right fix IMO.

One minor comment, not a blocker: the IPv6 path
rejects leading zeros in the prefix length
(getbits() returns 0 for inputs like '::1/024', due to the
"no leading zeros" check); maybe do the same for IPv4?

--
Best regards,
Roman Khapov

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-10-31 18:35:35 Re: O(N^3) planning time in choose_plan_name() since 8c49a484e8e
Previous Message Kirill Reshke 2026-10-31 17:45:24 Re: Speeding up GIST index creation for hstore