Skip to content

Commit 5517367

Browse files
committed
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 :-(.
1 parent e52cabf commit 5517367

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/backend/libpq/auth.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,10 +1615,12 @@ auth_peer(hbaPort *port)
16151615
pw = getpwuid(uid);
16161616
if (!pw)
16171617
{
1618+
int save_errno = errno;
1619+
16181620
ereport(LOG,
16191621
(errmsg("could not look up local user ID %ld: %s",
16201622
(long) uid,
1621-
errno ? strerror(errno) : _("user does not exist"))));
1623+
save_errno ? strerror(save_errno) : _("user does not exist"))));
16221624
return STATUS_ERROR;
16231625
}
16241626

0 commit comments

Comments
 (0)