pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #18712: inet value ::2 handling goes not as expected
4+ messages / 3 participants
[nested] [flat]

* BUG #18712: inet value ::2 handling goes not as expected
@ 2024-11-16 06:50  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 4+ messages in thread

From: PG Bug reporting form @ 2024-11-16 06:50 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: denis.feklushkin@gmail.com

The following bug has been logged on the website:

Bug reference:      18712
Logged by:          Denis Feklushkin
Email address:      denis.feklushkin@gmail.com
PostgreSQL version: 17.1
Operating system:   Debian
Description:        

I think that statement

select '::0.0.0.2'::inet;

should return '::0.0.0.2' value, not '::2'

I think this is what was intended in the Postgres sources. But it seems that
this line is never executed:
https://github.com/postgres/postgres/blob/7b88529f4363994450bd4cd3c172006a8a77e222/src/port/inet_net...



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #18712: inet value ::2 handling goes not as expected
@ 2024-11-17 17:05  Tom Lane <tgl@sss.pgh.pa.us>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2024-11-17 17:05 UTC (permalink / raw)
  To: denis.feklushkin@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
> I think that statement
> select '::0.0.0.2'::inet;
> should return '::0.0.0.2' value, not '::2'

> I think this is what was intended in the Postgres sources. But it seems that
> this line is never executed:
> https://github.com/postgres/postgres/blob/7b88529f4363994450bd4cd3c172006a8a77e222/src/port/inet_net...

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?

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #18712: inet value ::2 handling goes not as expected
@ 2024-11-18 05:17  Denis Feklushkin <feklushkin.denis@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Denis Feklushkin @ 2024-11-18 05:17 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: denis.feklushkin@gmail.com; pgsql-bugs@lists.postgresql.org

вс, 17 нояб. 2024 г. в 20:05, Tom Lane <tgl@sss.pgh.pa.us>:

> PG Bug reporting form <noreply@postgresql.org> writes:
> > I think that statement
> > select '::0.0.0.2'::inet;
> > should return '::0.0.0.2' value, not '::2'
>
> > I think this is what was intended in the Postgres sources. But it seems
> that
> > this line is never executed:
> >
> https://github.com/postgres/postgres/blob/7b88529f4363994450bd4cd3c172006a8a77e222/src/port/inet_net...
>
> 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.


Yes, this code block should be placed at first place inside of for loop


>   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...
Looks, they don't used 0x0001 check, so, they version was always as intended

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #18712: inet value ::2 handling goes not as expected
@ 2024-11-18 18:47  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Denis Feklushkin <feklushkin.denis@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2024-11-18 18:47 UTC (permalink / raw)
  To: Denis Feklushkin <feklushkin.denis@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org

Denis Feklushkin <feklushkin.denis@gmail.com> writes:
> вс, 17 нояб. 2024 г. в 20:05, Tom Lane <tgl@sss.pgh.pa.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...
> 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

Attachments:

ntoptest.c (text/x-c, 474B) download #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int main(int argc, char **argv) { char buf[16]; char formatted[128]; memset(buf, 0, sizeof(buf)); buf[15] = 0xff; inet_ntop(AF_INET6, buf, formatted, sizeof(formatted)); printf("::ff -> %s\n", formatted); buf[13] = 0xff; inet_ntop(AF_INET6, buf, formatted, sizeof(formatted)); printf("::ff:ff -> %s\n", formatted); return 0; }
^ permalink raw reply [nested|flat] 4+ messages in thread


end of thread, other threads:[~2024-11-18 18:47 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-11-16 06:50 BUG #18712: inet value ::2 handling goes not as expected PG Bug reporting form <noreply@postgresql.org>
2024-11-17 17:05 ` Tom Lane <tgl@sss.pgh.pa.us>
2024-11-18 05:17   ` Denis Feklushkin <feklushkin.denis@gmail.com>
2024-11-18 18:47     ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox