public inbox for [email protected]
help / color / mirror / Atom feedFrom: Heikki Linnakangas <[email protected]>
To: Peter Eisentraut <[email protected]>
To: pgsql-hackers <[email protected]>
Subject: Re: thread-safety: getpwuid_r()
Date: Sat, 24 Aug 2024 16:55:06 +0300
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
On 24/08/2024 11:42, Peter Eisentraut wrote:
> Here is a patch to replace a getpwuid() call in the backend, for
> thread-safety.
>
> This is AFAICT the only call in the getpw*() family that needs to be
> dealt with.
>
> (There is also a getgrnam() call, but that is called very early in the
> postmaster, before multiprocessing, so we can leave that as is.)
>
> The solution here is actually quite attractive: We can replace the
> getpwuid() call by the existing wrapper function pg_get_user_name(),
> which internally uses getpwuid_r(). This also makes the code a bit
> simpler. The same function is already used in libpq for a purpose that
> mirrors the backend use, so it's also nicer to use the same function for
> consistency.
Makes sense.
The temporary buffers are a bit funky. pg_get_user_name() internally
uses a BUFSIZE-sized area to hold the result of getpwuid_r(). If the
pg_get_user_name() caller passes a buffer smaller than BUFSIZE, the user
id might get truncated. I don't think that's a concern on any real-world
system, and the callers do pass a large-enough buffer so truncation
can't happen. At a minimum, it would be good to add a comment to
pg_get_user_name() along the lines of "if 'buflen' is smaller than
BUFSIZE, the result might be truncated".
Come to think of it, the pg_get_user_name() function is just a thin
wrapper around getpwuid_r(). It doesn't provide a lot of value. Perhaps
we should remove pg_get_user_name() and pg_get_user_home_dir()
altogether and call getpwuid_r() directly.
But no objection to committing this as it is, either.
--
Heikki Linnakangas
Neon (https://neon.tech)
view thread (3+ messages)
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: [email protected]
Cc: [email protected], [email protected]
Subject: Re: thread-safety: getpwuid_r()
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox