Re: BUG #18712: inet value ::2 handling goes not as expected

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Denis Feklushkin <feklushkin(dot)denis(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18712: inet value ::2 handling goes not as expected
Date: 2024-11-18 18:47:26
Message-ID: 3336104.1731955646@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Denis Feklushkin <feklushkin(dot)denis(at)gmail(dot)com> writes:
> вс, 17 нояб. 2024 г. в 20:05, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>> Hmm ... you are right that that code doesn't do what it seems to
>> intend to, because by the time that we get to this logic we have
>> i == 7 not i == 6.
>> But I'm not sure if we should change it after
>> all this time. We're about as likely to get complaints as kudos,
>> I fear. And the output isn't incorrect, just not-per-style.
>>
>> I wonder whether ISC ever changed their version?

> https://github.com/openbsd/src/blob/f7304f605db8e3a4de0a0d1c1488830678f77517/sys/netinet/inet_ntop.c#L196
> Looks, they don't used 0x0001 check, so, they version was always as intended

Well, that's OpenBSD's copy. I thought that the original code was
in BIND, but it doesn't seem to be there anymore, though there's
this tantalizing hint in the changelog from around 9.7.0:

bind-9.18.28/ChangeLog:2635. [bug] isc_inet_ntop() incorrectly handled 0.0/16 addresses.

However, I tried probing the actual behavior of various systems
with the attached test program. I got

::ff -> ::ff
::ff:ff -> ::0.255.0.255

on Linux, macOS, FreeBSD, NetBSD, and OpenBSD. So regardless of
original intent, this behavior seems to be the de facto standard.
I'm disinclined to make us deviate from it.

regards, tom lane

Attachment Content-Type Size
ntoptest.c text/x-c 475 bytes

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2024-11-19 00:28:02 BUG #18715: replace() function silently fails if 3rd argument is null
Previous Message PG Bug reporting form 2024-11-18 17:59:24 BUG #18714: error during installation