]> granicus.if.org Git - postgresql/commitdiff
Ensure _dosmaperr() actually sets errno correctly.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 23 Nov 2013 23:24:26 +0000 (18:24 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 23 Nov 2013 23:24:54 +0000 (18:24 -0500)
If logging is enabled, either ereport() or fprintf() might stomp on errno
internally, causing this function to return the wrong result.  That might
only end in a misleading error report, but in any code that's examining
errno to decide what to do next, the consequences could be far graver.

This has been broken since the very first version of this file in 2006
... it's a bit astonishing that we didn't identify this long ago.

Reported by Amit Kapila, though this isn't his proposed fix.

src/port/win32error.c

index f3e4f9227da3eb285344d0b8ffa535fb2d18ebc4..2ab5e8ace4cbaa72d2d1f17be68e3a4c64e60572 100644 (file)
@@ -175,14 +175,16 @@ _dosmaperr(unsigned long e)
        {
                if (doserrors[i].winerr == e)
                {
-                       errno = doserrors[i].doserr;
+                       int                     doserr = doserrors[i].doserr;
+
 #ifndef FRONTEND
                        ereport(DEBUG5,
                                        (errmsg_internal("mapped win32 error code %lu to %d",
-                                                                        e, errno)));
+                                                                        e, doserr)));
 #elif FRONTEND_DEBUG
-                       fprintf(stderr, _("mapped win32 error code %lu to %d"), e, errno);
+                       fprintf(stderr, _("mapped win32 error code %lu to %d"), e, doserr);
 #endif
+                       errno = doserr;
                        return;
                }
        }