1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Don't pass an invalid file handle to dup2(). That causes a crash on

Windows, thanks to a feature in CRT called Parameter Validation.

Backpatch to 8.2, which is the oldest version supported on Windows. In
8.2 and 8.3 also backpatch the earlier change to use DEVNULL instead of
NULL_DEV #define for a /dev/null-like device. NULL_DEV was hard-coded to
"/dev/null" regardless of platform, which didn't work on Windows, while
DEVNULL works on all platforms. Restarting syslogger didn't work on
Windows on versions 8.3 and below because of that.
This commit is contained in:
Heikki Linnakangas
2010-04-01 20:12:34 +00:00
parent d1bc3525c0
commit 292934de2f
3 changed files with 16 additions and 9 deletions

View File

@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.551.2.5 2009/12/02 17:41:31 tgl Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.551.2.6 2010/04/01 20:12:34 heikki Exp $
* *
* NOTES * NOTES
* *
@@ -1174,7 +1174,7 @@ pmdaemonize(void)
ExitPostmaster(1); ExitPostmaster(1);
} }
#endif #endif
i = open(NULL_DEV, O_RDWR, 0); i = open(DEVNULL, O_RDWR, 0);
dup2(i, 0); dup2(i, 0);
dup2(i, 1); dup2(i, 1);
dup2(i, 2); dup2(i, 2);

View File

@@ -18,7 +18,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.44.2.2 2009/11/19 02:45:50 tgl Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.44.2.3 2010/04/01 20:12:34 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -184,7 +184,7 @@ SysLoggerMain(int argc, char *argv[])
*/ */
if (redirection_done) if (redirection_done)
{ {
int fd = open(NULL_DEV, O_WRONLY, 0); int fd = open(DEVNULL, O_WRONLY, 0);
/* /*
* The closes might look redundant, but they are not: we want to be * The closes might look redundant, but they are not: we want to be
@@ -194,9 +194,12 @@ SysLoggerMain(int argc, char *argv[])
*/ */
close(fileno(stdout)); close(fileno(stdout));
close(fileno(stderr)); close(fileno(stderr));
dup2(fd, fileno(stdout)); if (fd != -1)
dup2(fd, fileno(stderr)); {
close(fd); dup2(fd, fileno(stdout));
dup2(fd, fileno(stderr));
close(fd);
}
} }
/* /*

View File

@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/c.h,v 1.222.2.2 2009/03/11 00:08:07 alvherre Exp $ * $PostgreSQL: pgsql/src/include/c.h,v 1.222.2.3 2010/04/01 20:12:34 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -762,7 +762,11 @@ typedef NameData *Name;
#include <unistd.h> #include <unistd.h>
#endif #endif
/* These are for things that are one way on Unix and another on NT */ /*
* This only works on Unix, not on Windows! This isn't used in PostgreSQL
* anymore, use the platform-aware DEVNULL instead. This is kept here just
* in case a 3rd party module uses it.
*/
#define NULL_DEV "/dev/null" #define NULL_DEV "/dev/null"
/* /*