Re: pg_getaddrinfo_all() with hintp=NULL

From: Sergey Tatarintsev <s(dot)tatarintsev(at)postgrespro(dot)ru>
To: Daniel Gustafsson <daniel(at)yesql(dot)se>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pg_getaddrinfo_all() with hintp=NULL
Date: 2025-11-12 08:46:33
Message-ID: dd0a6702-9469-4fd4-bb9a-cb529153b8ea@postgrespro.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

11.11.2025 23:23, Daniel Gustafsson пишет:
>> On 10 Nov 2025, at 06:14, Sergey Tatarintsev <s(dot)tatarintsev(at)postgrespro(dot)ru> wrote:
>> I'm trying to use pg_getaddrinfo_all() with NULL hints, but got segfault.
>> According to man(3) getaddrinfo, hints may be passed as NULL. In this case af_family
>> is equivalent to AF_UNSPEC.
> Right, but pg_getaddrinfo_all isn't getaddrinfo and doesn't claim to be. Since
> pg_getaddrinfo_all can return AF_UNIX as opposed to getaddrinfo, it's not clear
> why hints == NULL should mean ipv4|ipv6 here.
>
> Accepting NULL or also (subtly) breaks the API for pg_freeaddrinfo_all which is
> defined to take ai_family from the hints passed to pg_getaddrinfo_all. Now,
> reading the code makes it obvious that it will work anyways, but at the very
> least a patch to accept a NULL hint should update the function comment for
> pg_freeaddrinfo_all.
>
> --
> Daniel Gustafsson
>
Daniel, thanks for review!

I added a comment to pg_freeaddrinfo_all.
I don't think it made sense to comment that hint_ai_family simply
shouldn't be equal to AF_UNIX,
so I specified that if the original hints were NULL, hint_ai_family
should be equal to AF_UNSPEC.

--
With best regards,
Sergey Tatarintsev,
PostgresPro

Attachment Content-Type Size
v2-0001-Ability-to-pass-NULL-as-a-hintp-to-pg_getaddrinfo.patch text/x-patch 1.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Steven Niu 2025-11-12 08:47:20 Re: Fix incorrect assignment of InvalidXLogRecPtr to a non-LSN variable.
Previous Message Man Zeng 2025-11-12 08:45:16 Re: Extended Statistics set/restore/clear functions.