Skip to content

Commit ec6a6a2

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 4403229 commit ec6a6a2

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
@@ -175,14 +175,16 @@ _dosmaperr(unsigned long e)
175175
{
176176
if (doserrors[i].winerr == e)
177177
{
178-
errno = doserrors[i].doserr;
178+
int doserr = doserrors[i].doserr;
179+
179180
#ifndef FRONTEND
180181
ereport(DEBUG5,
181182
(errmsg_internal("mapped win32 error code %lu to %d",
182-
e, errno)));
183+
e, doserr)));
183184
#elif FRONTEND_DEBUG
184-
fprintf(stderr, _("mapped win32 error code %lu to %d"), e, errno);
185+
fprintf(stderr, _("mapped win32 error code %lu to %d"), e, doserr);
185186
#endif
187+
errno = doserr;
186188
return;
187189
}
188190
}

0 commit comments

Comments
 (0)