From bc68b30d208209d749522eaba79b0e124956bdde Mon Sep 17 00:00:00 2001 From: "Erich E. Hoover" Date: Sun, 15 Mar 2015 15:30:51 -0600 Subject: [PATCH] krnl386: Invalid console handles should translate into real handles when creating a new process. --- dlls/krnl386.exe16/file.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/dlls/krnl386.exe16/file.c b/dlls/krnl386.exe16/file.c index 158434006dd..6c3cef3534a 100644 --- a/dlls/krnl386.exe16/file.c +++ b/dlls/krnl386.exe16/file.c @@ -53,21 +53,26 @@ static HANDLE dos_handles[DOS_TABLE_SIZE]; */ static void FILE_InitProcessDosHandles( void ) { + HANDLE hStdInput, hStdOutput, hStdError, hNull; static BOOL init_done /* = FALSE */; HANDLE cp = GetCurrentProcess(); if (init_done) return; init_done = TRUE; - DuplicateHandle(cp, GetStdHandle(STD_INPUT_HANDLE), cp, &dos_handles[0], - 0, TRUE, DUPLICATE_SAME_ACCESS); - DuplicateHandle(cp, GetStdHandle(STD_OUTPUT_HANDLE), cp, &dos_handles[1], - 0, TRUE, DUPLICATE_SAME_ACCESS); - DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[2], - 0, TRUE, DUPLICATE_SAME_ACCESS); - DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[3], - 0, TRUE, DUPLICATE_SAME_ACCESS); - DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[4], - 0, TRUE, DUPLICATE_SAME_ACCESS); + hStdInput = GetStdHandle(STD_INPUT_HANDLE); + hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); + hStdError = GetStdHandle(STD_ERROR_HANDLE); + hNull = CreateFileA("NUL", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0); + /* Invalid console handles need to translate to real DOS handles in a new process */ + if (!hStdInput) hStdInput = hNull; + if (!hStdOutput) hStdOutput = hNull; + if (!hStdError) hStdError = hNull; + DuplicateHandle(cp, hStdInput, cp, &dos_handles[0], 0, TRUE, DUPLICATE_SAME_ACCESS); + DuplicateHandle(cp, hStdOutput, cp, &dos_handles[1], 0, TRUE, DUPLICATE_SAME_ACCESS); + DuplicateHandle(cp, hStdError, cp, &dos_handles[2], 0, TRUE, DUPLICATE_SAME_ACCESS); + DuplicateHandle(cp, hStdError, cp, &dos_handles[3], 0, TRUE, DUPLICATE_SAME_ACCESS); + DuplicateHandle(cp, hStdError, cp, &dos_handles[4], 0, TRUE, DUPLICATE_SAME_ACCESS); + CloseHandle(hNull); } /***********************************************************************