pgsql: Fix unportable use of getnameinfo() in pg_hba_file_rules view.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix unportable use of getnameinfo() in pg_hba_file_rules view.
Date: 2020-11-03 02:12:10
Message-ID: E1kZlnu-0007xz-9t@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix unportable use of getnameinfo() in pg_hba_file_rules view.

fill_hba_line() thought it could get away with passing sizeof(struct
sockaddr_storage) rather than the actual addrlen previously returned
by getaddrinfo(). While that appears to work on many platforms,
it does not work on FreeBSD 11: you get back a failure, which leads
to the view showing NULL for the address and netmask columns in all
rows. The POSIX spec for getnameinfo() is pretty clearly on
FreeBSD's side here: you should pass the actual address length.
So it seems plausible that there are other platforms where this
coding also fails, and we just hadn't noticed.

Also, IMO the fact that getnameinfo() failure leads to a NULL output
is pretty bogus in itself. Our pg_getnameinfo_all() wrapper is
careful to emit "???" on failure, and we should use that in such
cases. NULL should only be emitted in rows that don't have IP
addresses.

Per bug #16695 from Peter Vandivier. Back-patch to v10 where this
code was added.

Discussion: https://postgr.es/m/16695-a665558e2f630be7@postgresql.org

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/a58a631b4af0c027c07ea7cc4110a60b5f279ddf

Modified Files
--------------
src/backend/libpq/hba.c | 31 +++++++++++++++++++++----------
src/include/libpq/hba.h | 6 ++++++
2 files changed, 27 insertions(+), 10 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2020-11-03 03:15:29 pgsql: Fix typos.
Previous Message Tom Lane 2020-11-02 19:34:40 pgsql: Remove special checks for pg_rewrite.ev_qual and ev_action being