summaryrefslogtreecommitdiff
path: root/src/backend/libpq/auth.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-05-21 00:32:28 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-05-21 00:32:44 -0400
commit1545ca9a7463f4ae8451a845774a107ad0757a9f (patch)
treeaba0bdd55bbd4957a53a33b7079eef0e6389d32f /src/backend/libpq/auth.c
parent9c515f77d6cffb6f2576c5e9895cc0f29cc6279c (diff)
Fix unsafe usage of strerror(errno) within ereport().
This is the converse of the unsafe-usage-of-%m problem: the reason ereport/elog provide that format code is mainly to dodge the hazard of errno getting changed before control reaches functions within the arguments of the macro. I only found one instance of this hazard, but it's been there since 9.4 :-(.
Diffstat (limited to 'src/backend/libpq/auth.c')
-rw-r--r--src/backend/libpq/auth.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index be8c4776859..9c77701785f 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -1752,10 +1752,12 @@ auth_peer(hbaPort *port)
pw = getpwuid(uid);
if (!pw)
{
+ int save_errno = errno;
+
ereport(LOG,
(errmsg("could not look up local user ID %ld: %s",
(long) uid,
- errno ? strerror(errno) : _("user does not exist"))));
+ save_errno ? strerror(save_errno) : _("user does not exist"))));
return STATUS_ERROR;
}