From 571addd729a400cece396d79696adcc63387e43b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 29 Jan 2014 20:03:57 -0500 Subject: 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. --- src/common/username.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/common/username.c') diff --git a/src/common/username.c b/src/common/username.c index c6812ddd9d1..e946972a561 100644 --- a/src/common/username.c +++ b/src/common/username.c @@ -34,17 +34,17 @@ get_user_name(char **errstr) { #ifndef WIN32 struct passwd *pw; - uid_t user_id = geteuid(); + uid_t user_id = geteuid(); *errstr = NULL; - errno = 0; /* clear errno before call */ + errno = 0; /* clear errno before call */ pw = getpwuid(user_id); if (!pw) { - *errstr = psprintf(_("failed to look up effective user id %d: %s"), - (int) user_id, errno ? strerror(errno) : - _("user does not exist")); + *errstr = psprintf(_("failed to look up effective user id %ld: %s"), + (long) user_id, + errno ? strerror(errno) : _("user does not exist")); return NULL; } -- cgit v1.2.3