pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Denis Feklushkin <feklushkin.denis@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18712: inet value ::2 handling goes not as expected
Date: Mon, 18 Nov 2024 13:47:26 -0500
Message-ID: <3336104.1731955646@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHY2gWfDGqZHQB7nKhtmPGBGYxvhS5OqY4k_BaAP5PSwHyW8Tg@mail.gmail.com>
References: <18712-f787a146022a78e4@postgresql.org>
	<3065772.1731863111@sss.pgh.pa.us>
	<CAHY2gWfDGqZHQB7nKhtmPGBGYxvhS5OqY4k_BaAP5PSwHyW8Tg@mail.gmail.com>

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; }

view thread (4+ messages)

Message-ID: <3336104.1731955646@sss.pgh.pa.us>
Permalink:  ../3336104.1731955646@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3336104.1731955646@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, feklushkin.denis@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18712: inet value ::2 handling goes not as expected
  In-Reply-To: <3336104.1731955646@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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