Paul Gofman : msvcrt: Ignore inherited FDs with invalid handles in msvcrt_init_io().

Alexandre Julliard julliard at winehq.org
Mon Feb 15 16:09:51 CST 2021


Module: wine
Branch: master
Commit: 611742d31fb042d642d5ac30eebf0d73154a3481
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=611742d31fb042d642d5ac30eebf0d73154a3481

Author: Paul Gofman <pgofman at codeweavers.com>
Date:   Mon Feb 15 17:52:16 2021 +0300

msvcrt: Ignore inherited FDs with invalid handles in msvcrt_init_io().

The process std handles should be preserved in this case.

Fixes error on startup in "Re:ZERO -Starting Life in Another World- The
Prophecy of the Throne" launcher.

Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcrt/file.c       |  2 +-
 dlls/msvcrt/tests/file.c | 36 +++++++++++++++++++++++++++++++++---
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 73e1a82476f..89d6e7d721f 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -586,7 +586,7 @@ void msvcrt_init_io(void)
     count = min(count, MSVCRT_MAX_FILES);
     for (i = 0; i < count; i++)
     {
-      if ((*wxflag_ptr & WX_OPEN) && *handle_ptr != INVALID_HANDLE_VALUE)
+      if ((*wxflag_ptr & WX_OPEN) && GetFileType(*handle_ptr) != FILE_TYPE_UNKNOWN)
       {
         fdinfo = get_ioinfo_alloc_fd(i);
         if(fdinfo != &MSVCRT___badioinfo)
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index 0cf8bad124f..fb242d81282 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -1454,13 +1454,27 @@ static void test_file_write_read( void )
   free(tempf);
 }
 
-static void test_file_inherit_child(const char* fd_s)
+static void test_file_inherit_child(const char* fd_s, const char *handle_str)
 {
+    HANDLE handle_value;
     int fd = atoi(fd_s);
+    HANDLE *handle_ptr;
+    unsigned int count;
     char buffer[32];
+    STARTUPINFOA si;
     int ret;
 
-    ret =write(fd, "Success", 8);
+    GetStartupInfoA(&si);
+    count = *(unsigned *)si.lpReserved2;
+    if (handle_str)
+    {
+        ok(count == 3, "Got unexpected count %u.\n", count);
+        sscanf(handle_str, "%p", &handle_value);
+        handle_ptr = (HANDLE *)(si.lpReserved2 + sizeof(unsigned) + count);
+        ok(handle_value == handle_ptr[1], "Got unexpected handle %p.\n", handle_ptr[1]);
+    }
+
+    ret = write(fd, "Success", 8);
     ok( ret == 8, "Couldn't write in child process on %d (%s)\n", fd, strerror(errno));
     lseek(fd, 0, SEEK_SET);
     ok(read(fd, buffer, sizeof (buffer)) == 8, "Couldn't read back the data\n");
@@ -1643,6 +1657,22 @@ static void test_file_inherit( const char* selfname )
     test_stdout_handle( &startup, cmdline, handles[1], TRUE, "large size block" );
     CloseHandle( handles[1] );
     DeleteFileA("fdopen.tst");
+
+    /* test inherit block with invalid handle */
+    handles[1] = INVALID_HANDLE_VALUE;
+    create_io_inherit_block( &startup, 3, handles );
+    sprintf(cmdline, "%s file inherit 1 %p", selfname, handles[1]);
+    test_stdout_handle( &startup, cmdline, NULL, FALSE, "INVALID_HANDLE_VALUE stdout handle" );
+
+    handles[1] = NULL;
+    create_io_inherit_block( &startup, 3, handles );
+    sprintf(cmdline, "%s file inherit 1 %p", selfname, handles[1]);
+    test_stdout_handle( &startup, cmdline, NULL, FALSE, "NULL stdout handle" );
+
+    handles[1] = (void *)0xdeadbeef;
+    create_io_inherit_block( &startup, 3, handles );
+    sprintf(cmdline, "%s file inherit 1 %p", selfname, handles[1]);
+    test_stdout_handle( &startup, cmdline, NULL, FALSE, "invalid stdout handle" );
 }
 
 static void test_invalid_stdin_child( void )
@@ -2714,7 +2744,7 @@ START_TEST(file)
     if (arg_c >= 3)
     {
         if (strcmp(arg_v[2], "inherit") == 0)
-            test_file_inherit_child(arg_v[3]);
+            test_file_inherit_child(arg_v[3], arg_c > 4 ? arg_v[4] : NULL);
         else if (strcmp(arg_v[2], "inherit_no") == 0)
             test_file_inherit_child_no(arg_v[3]);
         else if (strcmp(arg_v[2], "pipes") == 0)




More information about the wine-cvs mailing list