msvcrt: dont overwrite the standard streams (with test, try 6)
André Hentschel
nerv at dawncrow.de
Sun Sep 6 09:55:13 CDT 2009
Some Apps e.g. mingw-apps use lpReserved2 to pass some data to the child-process, this data starts with 4 Byte of Zeros(unsinged 0) to tell msvcrt not to read that as an inherit-block.
See also Bug 18479
try 5 to try 6: see http://www.winehq.org/pipermail/wine-devel/2009-September/078395.html
---
dlls/msvcrt/file.c | 2 +-
dlls/msvcrt/tests/file.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 6671f2f..12ebd2c 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -349,7 +349,7 @@ void msvcrt_init_io(void)
InitializeCriticalSection(&MSVCRT_file_cs);
MSVCRT_file_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": MSVCRT_file_cs");
GetStartupInfoA(&si);
- if (si.cbReserved2 != 0 && si.lpReserved2 != NULL)
+ if (si.cbReserved2 >= sizeof(unsigned) && si.lpReserved2 != NULL && *(unsigned*)si.lpReserved2)
{
char* wxflag_ptr;
HANDLE* handle_ptr;
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index d405656..3df2956 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -863,6 +863,13 @@ static void test_file_inherit( const char* selfname )
int fd;
const char* arg_v[5];
char buffer[16];
+ char cmdline[MAX_PATH];
+ BYTE empty[sizeof(unsigned) + sizeof(char) + sizeof(HANDLE)];
+ STARTUPINFO startup;
+ SECURITY_ATTRIBUTES sa;
+ PROCESS_INFORMATION proc;
+ HANDLE hFile;
+ DWORD ret;
fd = open ("fdopen.tst", O_CREAT | O_RDWR | O_BINARY, _S_IREAD |_S_IWRITE);
ok(fd != -1, "Couldn't create test file\n");
@@ -890,6 +897,38 @@ static void test_file_inherit( const char* selfname )
ok(read(fd, buffer, sizeof (buffer)) == 0, "Found unexpected data (%s)\n", buffer);
close (fd);
ok(unlink("fdopen.tst") == 0, "Couldn't unlink\n");
+
+ /* make file handle inheritable */
+ sa.nLength = sizeof(sa);
+ sa.lpSecurityDescriptor = NULL;
+ sa.bInheritHandle = TRUE;
+ hFile = CreateFileA( "fdopen.tst", GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ &sa, CREATE_ALWAYS, 0, NULL );
+
+ /* pass a empty Reserved2, which should not be recognized as inherit-block */
+ ZeroMemory(&startup, sizeof(STARTUPINFO));
+ ZeroMemory(empty, sizeof(empty));
+ startup.cb = sizeof(startup);
+ startup.cbReserved2 = sizeof(empty);
+ startup.lpReserved2 = empty;
+
+ /* in case it fails pipe the stdout to a file */
+ startup.dwFlags = STARTF_USESTDHANDLES;
+ startup.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
+ startup.hStdOutput = hFile;
+ startup.hStdError = GetStdHandle( STD_ERROR_HANDLE );
+
+ sprintf(cmdline, "%s file inherit_ow", selfname);
+ CreateProcessA(NULL, cmdline, NULL, NULL, TRUE,
+ CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &proc);
+ winetest_wait_child_process( proc.hProcess );
+
+ SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
+ ReadFile(hFile, buffer, 8, &ret, NULL);
+ CloseHandle(hFile);
+ ok(strcmp(buffer, "Success") == 0 && ret==8, "Found unexpected data (%s)\n", buffer);
+ ok(unlink("fdopen.tst") == 0, "Couldn't unlink\n");
}
static void test_tmpnam( void )
@@ -1223,6 +1262,12 @@ START_TEST(file)
test_file_inherit_child(arg_v[3]);
else if (strcmp(arg_v[2], "inherit_no") == 0)
test_file_inherit_child_no(arg_v[3]);
+ else if (strcmp(arg_v[2], "inherit_ow") == 0)
+ {
+ char stdfd[2];
+ sprintf(stdfd, "%d", STDOUT_FILENO);
+ test_file_inherit_child(stdfd);
+ }
else if (strcmp(arg_v[2], "pipes") == 0)
test_pipes_child(arg_c, arg_v);
else
--
Best Regards, André Hentschel
More information about the wine-patches
mailing list