]> granicus.if.org Git - postgresql/commitdiff
Fix unsafe usage of strerror(errno) within ereport().
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 21 May 2018 04:32:28 +0000 (00:32 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 21 May 2018 04:32:39 +0000 (00:32 -0400)
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

index 10e92b458e1ed24669d0ef4e4f658b9b603823cf..1907f88bc18e4dcb3fbda2f2bc65ac02173c63c4 100644 (file)
@@ -2017,10 +2017,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;
        }