postgres.git / summary / log / commit / refs
commit 5517367e978b29dedb1ca0e84a0285b8f9446fde
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Mon May 21 04:32:28 2018 +0000
First released in: 11.0, 9.4.19, 9.5.14, 9.6.10, 10.5
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 :-(.
src/backend/libpq/auth.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index f9d4488d569..ce0d45ae739 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -1615,10 +1615,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;
}
[parent: e52cabff7054]