From: Tom Lane Date: Mon, 21 May 2018 04:32:28 +0000 (-0400) Subject: Fix unsafe usage of strerror(errno) within ereport(). X-Git-Tag: REL_11_BETA1~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=81256cd05f0745353c6572362155b57250a0d2a0;p=thirdparty%2Fpostgresql.git 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 :-(. --- diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index 3014b17a7c1..63f37902e64 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -2041,10 +2041,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; }