Skip to content

Commit 69eb861

Browse files
committed
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.
1 parent 0f8ff3e commit 69eb861

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/port/win32error.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,16 @@ _dosmaperr(unsigned long e)
179179
{
180180
if (doserrors[i].winerr == e)
181181
{
182-
errno = doserrors[i].doserr;
182+
int doserr = doserrors[i].doserr;
183+
183184
#ifndef FRONTEND
184185
ereport(DEBUG5,
185186
(errmsg_internal("mapped win32 error code %lu to %d",
186-
e, errno)));
187+
e, doserr)));
187188
#elif FRONTEND_DEBUG
188-
fprintf(stderr, _("mapped win32 error code %lu to %d"), e, errno);
189+
fprintf(stderr, _("mapped win32 error code %lu to %d"), e, doserr);
189190
#endif
191+
errno = doserr;
190192
return;
191193
}
192194
}

0 commit comments

Comments
 (0)