diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-11-23 18:24:26 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-11-23 18:24:26 -0500 |
commit | f145454d57bc9dfd105f7236a03a00dd25395dd2 (patch) | |
tree | 781d6a974bd11aa9a200b1e72100e9b973aec5f5 | |
parent | b7212c9726ee4bdf0ddd938742f03e86d8c431bf (diff) | |
download | postgresql-f145454d57bc9dfd105f7236a03a00dd25395dd2.tar.gz postgresql-f145454d57bc9dfd105f7236a03a00dd25395dd2.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.
-rw-r--r-- | src/port/win32error.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/port/win32error.c b/src/port/win32error.c index 2222be89071..5c49b38a5e7 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; } } |