pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
LibPQ doesn't say host=* translates to localhost
6+ messages / 3 participants
[nested] [flat]

* LibPQ doesn't say host=* translates to localhost
@ 2024-06-27 19:56 David G. Johnston <david.g.johnston@gmail.com>
  2024-06-27 20:42 ` Re: LibPQ doesn't say host=* translates to localhost Tom Lane <tgl@sss.pgh.pa.us>
  2024-06-28 07:47 ` Re: LibPQ doesn't say host=* translates to localhost Francisco Olarte <folarte@peoplecall.com>
  0 siblings, 2 replies; 6+ messages in thread

From: David G. Johnston @ 2024-06-27 19:56 UTC (permalink / raw)
  To: PostgreSQL Bug List <pgsql-bugs@lists.postgresql.org>

The documentation [0] doesn't say this should work and general networking
knowledge leads me to believe it wouldn't [1].

PGHOST='*' psql postgres
psql (17beta1)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384,
compression: off, ALPN: postgresql)
Type "help" for help.

postgres=# \conninfo
You are connected to database "postgres" as user "davidj" on host "*"
(address "127.0.0.1") at port "5432".
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384,
compression: off, ALPN: postgresql)

David J.

[0]
https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS

[1]
ping *
ping: src: Temporary failure in name resolution

ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.026 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.031 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.028 ms

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

* Re: LibPQ doesn't say host=* translates to localhost
  2024-06-27 19:56 LibPQ doesn't say host=* translates to localhost David G. Johnston <david.g.johnston@gmail.com>
@ 2024-06-27 20:42 ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 6+ messages in thread

From: Tom Lane @ 2024-06-27 20:42 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: PostgreSQL Bug List <pgsql-bugs@lists.postgresql.org>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> The documentation [0] doesn't say this should work and general networking
> knowledge leads me to believe it wouldn't [1].

> PGHOST='*' psql postgres
> psql (17beta1)

Seems to be an undocumented glibc-ism.  That works for me on RHEL8,
but not on macOS:

$ psql -h '*'
psql: error: could not translate host name "*" to address: nodename nor servname provided, or not known

The POSIX spec for getaddrinfo(3) doesn't suggest it should
work, either.

			regards, tom lane





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

* Re: LibPQ doesn't say host=* translates to localhost
  2024-06-27 19:56 LibPQ doesn't say host=* translates to localhost David G. Johnston <david.g.johnston@gmail.com>
@ 2024-06-28 07:47 ` Francisco Olarte <folarte@peoplecall.com>
  2024-06-28 16:11   ` Re: LibPQ doesn't say host=* translates to localhost David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Francisco Olarte @ 2024-06-28 07:47 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: PostgreSQL Bug List <pgsql-bugs@lists.postgresql.org>

On Thu, 27 Jun 2024 at 21:57, David G. Johnston
<david.g.johnston@gmail.com> wrote:
> The documentation [0] doesn't say this should work and general networking knowledge leads me to believe it wouldn't [1].
>
> PGHOST='*' psql postgres
> psql (17beta1)
> SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: postgresql)
> Type "help" for help.
>
> postgres=# \conninfo
> You are connected to database "postgres" as user "davidj" on host "*" (address "127.0.0.1") at port "5432".
> SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: postgresql)
>
> David J.
>
> [0] https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
>
> [1]
> ping *
> ping: src: Temporary failure in name resolution

Bad quoting, PGHOST=¡*', single quoted, but ping *, unquouted, with an
error message which hints at <<echo ping *>> giving back <<ping src
....>>

Bug may be real, but ping '*' could give some better data for debugging.

Francisco Olarte.





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

* Re: LibPQ doesn't say host=* translates to localhost
  2024-06-27 19:56 LibPQ doesn't say host=* translates to localhost David G. Johnston <david.g.johnston@gmail.com>
  2024-06-28 07:47 ` Re: LibPQ doesn't say host=* translates to localhost Francisco Olarte <folarte@peoplecall.com>
@ 2024-06-28 16:11   ` David G. Johnston <david.g.johnston@gmail.com>
  2024-06-28 16:56     ` Re: LibPQ doesn't say host=* translates to localhost Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 6+ messages in thread

From: David G. Johnston @ 2024-06-28 16:11 UTC (permalink / raw)
  To: Francisco Olarte <folarte@peoplecall.com>; +Cc: PostgreSQL Bug List <pgsql-bugs@lists.postgresql.org>

On Fri, Jun 28, 2024 at 12:48 AM Francisco Olarte <folarte@peoplecall.com>
wrote:

> On Thu, 27 Jun 2024 at 21:57, David G. Johnston
> <david.g.johnston@gmail.com> wrote:
> > The documentation [0] doesn't say this should work and general
> networking knowledge leads me to believe it wouldn't [1].
> >
> > PGHOST='*' psql postgres
> > psql (17beta1)
> > SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384,
> compression: off, ALPN: postgresql)
> > Type "help" for help.
> >
> > postgres=# \conninfo
> > You are connected to database "postgres" as user "davidj" on host "*"
> (address "127.0.0.1") at port "5432".
> > SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384,
> compression: off, ALPN: postgresql)
> >
> > David J.
> >
> > [0]
> https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
> >
> > [1]
> > ping *
> > ping: src: Temporary failure in name resolution
>
> Bad quoting, PGHOST=¡*', single quoted, but ping *, unquouted, with an
> error message which hints at <<echo ping *>> giving back <<ping src
> ....>>
>
> Bug may be real, but ping '*' could give some better data for debugging.
>
>
Good catch.

ping '*'
ping: *: Name or service not known

This is Ubuntu.

I'm fine with not documenting this if we are delegating to some underlying
library that makes the behavior platform-specific (though maybe document
that...even though it now seems obvious to me in retrospect).  I just
thought since ping didn't work we were doing something in between to avoid
the issue.

David J.

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

* Re: LibPQ doesn't say host=* translates to localhost
  2024-06-27 19:56 LibPQ doesn't say host=* translates to localhost David G. Johnston <david.g.johnston@gmail.com>
  2024-06-28 07:47 ` Re: LibPQ doesn't say host=* translates to localhost Francisco Olarte <folarte@peoplecall.com>
  2024-06-28 16:11   ` Re: LibPQ doesn't say host=* translates to localhost David G. Johnston <david.g.johnston@gmail.com>
@ 2024-06-28 16:56     ` Tom Lane <tgl@sss.pgh.pa.us>
  2024-06-30 09:52       ` Re: LibPQ doesn't say host=* translates to localhost Francisco Olarte <folarte@peoplecall.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Tom Lane @ 2024-06-28 16:56 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Francisco Olarte <folarte@peoplecall.com>; PostgreSQL Bug List <pgsql-bugs@lists.postgresql.org>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> Good catch.

> ping '*'
> ping: *: Name or service not known

> This is Ubuntu.

Yeah, I see the same on a couple different Red Hat versions.  Very
interesting, since it implies that ping is using something other than
getaddrinfo(3) to resolve the hostname.  I'm not quite interested
enough to go find out what, though.

			regards, tom lane





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

* Re: LibPQ doesn't say host=* translates to localhost
  2024-06-27 19:56 LibPQ doesn't say host=* translates to localhost David G. Johnston <david.g.johnston@gmail.com>
  2024-06-28 07:47 ` Re: LibPQ doesn't say host=* translates to localhost Francisco Olarte <folarte@peoplecall.com>
  2024-06-28 16:11   ` Re: LibPQ doesn't say host=* translates to localhost David G. Johnston <david.g.johnston@gmail.com>
  2024-06-28 16:56     ` Re: LibPQ doesn't say host=* translates to localhost Tom Lane <tgl@sss.pgh.pa.us>
@ 2024-06-30 09:52       ` Francisco Olarte <folarte@peoplecall.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Francisco Olarte @ 2024-06-30 09:52 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: David G. Johnston <david.g.johnston@gmail.com>; PostgreSQL Bug List <pgsql-bugs@lists.postgresql.org>

On Fri, 28 Jun 2024 at 18:56, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > ping '*'
> > ping: *: Name or service not known
> > This is Ubuntu.
> Yeah, I see the same on a couple different Red Hat versions.  Very
> interesting, since it implies that ping is using something other than
> getaddrinfo(3) to resolve the hostname.  I'm not quite interested
> enough to go find out what, though.

Same in Debian, as expected.

But it picked my curiosity, so I did an ltrace:

$ sudo ltrace ping '*' |& fgrep addrinfo
getaddrinfo("*", nil, 0x7ffde84578c0, 0x7ffde84578a8) = -2

And did this little perl experiment....
>>> addrinfo.pl
use strict;
use Socket qw(:addrinfo);

sub U($) { $_[0] // 'undef'; }
sub M($) {
    my $h = shift;
    join ';', map { "$_=>".U($h->{$_}) }  sort keys %$h;
}

sub pai {
    my ($host, $service, $hints)=@_;
    printf "gai(%s,%s,{%s})\n",
    $host, U $service, M $hints;
    my ($err, @addr) = getaddrinfo($host, $service, $hints);
    printf "  err=%s\n", $err//'UNDEF';
    while(my ($i, $v)=each @addr) {
    printf "  a[%d]={%s},addr=%s\n",
        $i, M $v,
        unpack("h*",$v->{addr});
    }
}


pai('*',undef,{});
pai('*',undef,{family=>Socket::AF_INET});
pai('*',5432, {family=>Socket::AF_INET});
<<<
Which gives:
>>>
$ perl -w addrinfo.pl
gai(*,undef,{})
  err=Name or service not known
gai(*,undef,{family=>2})
  err=Name or service not known
gai(*,5432,{family=>2})
  err=
  a[0]={addr=>8;canonname=>undef;family=>2;protocol=>6;socktype=>1},addr=20005183f70000100000000000000000
  a[1]={addr=>8;canonname=>undef;family=>2;protocol=>17;socktype=>2},addr=20005183f70000100000000000000000
  a[2]={addr=>8;canonname=>undef;family=>2;protocol=>0;socktype=>3},addr=20005183f70000100000000000000000
<<<
I am not sure how to follow, or if perl uses glibc, and have to go
AFK, and I am not sure if it relates, but getaddrinfo may be doing
strange things.

Francisco Olarte.





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


end of thread, other threads:[~2024-06-30 09:52 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-06-27 19:56 LibPQ doesn't say host=* translates to localhost David G. Johnston <david.g.johnston@gmail.com>
2024-06-27 20:42 ` Tom Lane <tgl@sss.pgh.pa.us>
2024-06-28 07:47 ` Francisco Olarte <folarte@peoplecall.com>
2024-06-28 16:11   ` David G. Johnston <david.g.johnston@gmail.com>
2024-06-28 16:56     ` Tom Lane <tgl@sss.pgh.pa.us>
2024-06-30 09:52       ` Francisco Olarte <folarte@peoplecall.com>

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