mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Fix unsafe references to errno within error messaging logic.
Various places were supposing that errno could be expected to hold still within an ereport() nest or similar contexts. This isn't true necessarily, though in some cases it accidentally failed to fail depending on how the compiler chanced to order the subexpressions. This class of thinko explains recent reports of odd failures on clang-built versions, typically missing or inappropriate HINT fields in messages. Problem identified by Christian Kruse, who also submitted the patch this commit is based on. (I fixed a few issues in his patch and found a couple of additional places with the same disease.) Back-patch as appropriate to all supported branches.
This commit is contained in:
@ -264,14 +264,15 @@ exec_command(const char *cmd,
|
||||
{
|
||||
#ifndef WIN32
|
||||
struct passwd *pw;
|
||||
uid_t user_id = geteuid();
|
||||
|
||||
errno = 0; /* clear errno before call */
|
||||
pw = getpwuid(geteuid());
|
||||
errno = 0; /* clear errno before call */
|
||||
pw = getpwuid(user_id);
|
||||
if (!pw)
|
||||
{
|
||||
psql_error("could not get home directory for user id %d: %s\n",
|
||||
(int) geteuid(), errno ?
|
||||
strerror(errno) : "user does not exist");
|
||||
psql_error("could not get home directory for user id %ld: %s\n",
|
||||
(long) user_id,
|
||||
errno ? strerror(errno) : _("user does not exist"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
dir = pw->pw_dir;
|
||||
|
Reference in New Issue
Block a user