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

From: Iliia Khaprov <i(dot)khaprov(at)gmail(dot)com>
To: Roman Khapov <rkhapov(at)yandex-team(dot)ru>
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-11-02 21:00:00
Message-ID: CAFO+O_oEV9Q6r0RNhrmC60KrdpLp0sOEFLRFtcuXvfCtW_enxA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Roman,

Thanks for looking into this.
I thought about leading zeros, but abandoned it - maybe somebody
relies on this quirk.

Best regards,
Iliia

On Sat, Oct 31, 2026 at 7:08 PM Roman Khapov <rkhapov(at)yandex-team(dot)ru> wrote:
>
> 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrey Rachitskiy 2026-11-02 21:12:42 Re: inet/cidr: IPv4 prefix length overflows int and passes the range check
Previous Message Prashant Chinnam 2026-11-02 20:49:34 Re: [PATCH] pgcrypto: Fix sha-crypt rounds= values that do not fit in int (BUG #19743)