diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-01-29 20:03:57 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-01-29 20:04:43 -0500 |
commit | 571addd729a400cece396d79696adcc63387e43b (patch) | |
tree | 5444989203f8b2633295a23cf8737c626ba10da6 /src/bin/psql/command.c | |
parent | 120c5cc761e0d99a9a2f3349f4031850b0dbd5a0 (diff) |
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.
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r-- | src/bin/psql/command.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index b26e28006ec..764534a3ae0 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -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; |