aboutsummaryrefslogtreecommitdiff
path: root/src/port/win32error.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-11-23 18:24:26 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2013-11-23 18:24:50 -0500
commitb2502ecef92c598f6d71d80b8a5745d252cfdde5 (patch)
tree6681a5c7096ef0af8470de37a00ccf5b4465cf0d /src/port/win32error.c
parente1f7173ea19ad8977311dc72fe50492fae5c078d (diff)
downloadpostgresql-b2502ecef92c598f6d71d80b8a5745d252cfdde5.tar.gz
postgresql-b2502ecef92c598f6d71d80b8a5745d252cfdde5.zip
Ensure _dosmaperr() actually sets errno correctly.
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.
Diffstat (limited to 'src/port/win32error.c')
-rw-r--r--src/port/win32error.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/port/win32error.c b/src/port/win32error.c
index 4b3b1ea7d6e..32a9aec61e6 100644
--- a/src/port/win32error.c
+++ b/src/port/win32error.c
@@ -179,14 +179,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;
}
}