Skip to content

Commit 28782d7

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 fa2cfb9 commit 28782d7

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
@@ -2017,10 +2017,12 @@ auth_peer(hbaPort *port)
20172017
pw = getpwuid(uid);
20182018
if (!pw)
20192019
{
2020+
int save_errno = errno;
2021+
20202022
ereport(LOG,
20212023
(errmsg("could not look up local user ID %ld: %s",
20222024
(long) uid,
2023-
errno ? strerror(errno) : _("user does not exist"))));
2025+
save_errno ? strerror(save_errno) : _("user does not exist"))));
20242026
return STATUS_ERROR;
20252027
}
20262028

0 commit comments

Comments
 (0)