[PATCH V2] dlls/kernel32/tests: test when passing non inheritable handles in CreateProcess

Eric Pouech eric.pouech at gmail.com
Wed Apr 20 06:22:56 CDT 2022


V2:
- fix broken results on Win7

note: a couple of errors reported by Marvin when running these tests are fixed by
the other 2 patch-serie (and others have been present on Debian from some locale)

Signed-off-by: Eric Pouech <eric.pouech at gmail.com>

---
 dlls/kernel32/tests/process.c |   89 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)

diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c
index ebadc2e8d12..446a2b25713 100644
--- a/dlls/kernel32/tests/process.c
+++ b/dlls/kernel32/tests/process.c
@@ -512,7 +512,22 @@ static void     doChild(const char* file, const char* option)
             ok(WriteFile(hStdOut, buf, r, &w, NULL) && w == r, "Writing message to output pipe\n");
         }
     }
+    if (option && strcmp(option, "stdinfo") == 0)
+    {
+        DWORD flin, flout, flerr;
 
+        BOOL bin  = GetHandleInformation(GetStdHandle(STD_INPUT_HANDLE), &flin);
+        BOOL bout = GetHandleInformation(GetStdHandle(STD_OUTPUT_HANDLE), &flout);
+        BOOL berr = GetHandleInformation(GetStdHandle(STD_ERROR_HANDLE), &flerr);
+        if (bin || bout || berr)
+        {
+            childPrintf(hFile, "[StdHandleInfo]\n");
+            if (bin ) childPrintf(hFile, "hStdInput=%lu",  flin);
+            if (bout) childPrintf(hFile, "hStdOutput=%lu", flout);
+            if (berr) childPrintf(hFile, "hStdError=%lu",  flerr);
+            childPrintf(hFile, "\n");
+        }
+    }
     if (option && strcmp(option, "exit_code") == 0)
     {
         childPrintf(hFile, "[ExitCode]\nvalue=%d\n\n", 123);
@@ -523,6 +538,15 @@ static void     doChild(const char* file, const char* option)
     CloseHandle(hFile);
 }
 
+static BOOL isChildPresent( const char* sect, const char* key )
+{
+    char        buf[1024+4*MAX_LISTED_ENV_VAR];
+
+    GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
+    if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return FALSE;
+    return TRUE;
+}
+
 static char* getChildString(const char* sect, const char* key)
 {
     char        buf[1024+4*MAX_LISTED_ENV_VAR];
@@ -614,10 +638,17 @@ static void ok_child_int( int line, const char *sect, const char *key, UINT expe
     ok_(__FILE__, line)( result == expect, "%s:%s expected %u, but got %u\n", sect, key, expect, result );
 }
 
+static void ok_child_intbrk( int line, const char *sect, const char *key, UINT expect, UINT brk )
+{
+    UINT result = GetPrivateProfileIntA( sect, key, !expect, resfile );
+    ok_(__FILE__, line)( result == expect || broken(result == brk), "%s:%s expected %u, but got %u\n", sect, key, expect, result );
+}
+
 #define okChildString(sect, key, expect) ok_child_string(__LINE__, (sect), (key), (expect), 1 )
 #define okChildIString(sect, key, expect) ok_child_string(__LINE__, (sect), (key), (expect), 0 )
 #define okChildStringWA(sect, key, expect) ok_child_stringWA(__LINE__, (sect), (key), (expect), 1 )
 #define okChildInt(sect, key, expect) ok_child_int(__LINE__, (sect), (key), (expect))
+#define okChildIntBroken(sect, key, expect, brk) ok_child_intbrk(__LINE__, (sect), (key), (expect), (brk))
 
 static void test_Startup(void)
 {
@@ -1691,6 +1722,64 @@ static void test_Console(void)
 
     release_memory();
     DeleteFileA(resfile);
+
+    /* test passing in startupinfo inheritable and non inheritable handles (CreateProcess not inheriting handles) */
+    memset(&startup, 0, sizeof(startup));
+    startup.cb = sizeof(startup);
+    startup.dwFlags = STARTF_USESTDHANDLES;
+    startup.hStdInput = CreateFileA("NUL", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
+    startup.hStdOutput = CreateFileA("NUL", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
+    startup.hStdError = (HANDLE)(DWORD_PTR)0x00585840;
+    ok(startup.hStdInput != INVALID_HANDLE_VALUE, "failed to open NUL\n");
+    ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "failed to open NUL\n");
+    sprintf(buffer, "\"%s\" process dump \"%s\" stdinfo", selfname, resfile);
+    ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
+    wait_and_close_child_process(&info);
+    CloseHandle(startup.hStdInput);
+
+    reload_child_info(resfile);
+    /* handles values have been zero:ed */
+    todo_wine okChildIntBroken("StartupInfoA", "hStdInput",  0, /* Win7 */ (DWORD_PTR)startup.hStdInput);
+    todo_wine okChildIntBroken("StartupInfoA", "hStdOutput", 0, /* Win7 */ (DWORD_PTR)startup.hStdOutput);
+    todo_wine okChildIntBroken("StartupInfoA", "hStdError",  0, /* Win7 */ (DWORD_PTR)startup.hStdError);
+    todo_wine okChildIntBroken("StartupInfoW", "hStdInput",  0, /* Win7 */ (DWORD_PTR)startup.hStdInput);
+    todo_wine okChildIntBroken("StartupInfoW", "hStdOutput", 0, /* Win7 */ (DWORD_PTR)startup.hStdOutput);
+    todo_wine okChildIntBroken("StartupInfoW", "hStdError",  0, /* Win7 */ (DWORD_PTR)startup.hStdError);
+    /* even inheritable objects are not inherited */
+    todo_wine ok(!isChildPresent("StdHandleInfo", "hStdInput"), "shouldn't inherit handle\n");
+    ok(!isChildPresent("StdHandleInfo", "hStdOutput"), "hStdOutput shouldn't be present\n");
+    ok(!isChildPresent("StdHandleInfo", "hStdError"), "hStdError shouldn't be present\n");
+    release_memory();
+    DeleteFileA(resfile);
+
+    /* test passing in startupinfo inheritable and non inheritable handles (CreateProcess inhering handles)) */
+    memset(&startup, 0, sizeof(startup));
+    startup.cb = sizeof(startup);
+    startup.dwFlags = STARTF_USESTDHANDLES;
+    startup.hStdInput = CreateFileA("NUL", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
+    startup.hStdOutput = CreateFileA("NUL", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
+    startup.hStdError = (HANDLE)(DWORD_PTR)0x00585840;
+    ok(startup.hStdInput != INVALID_HANDLE_VALUE, "failed to open NUL\n");
+    ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "failed to open NUL\n");
+    sprintf(buffer, "\"%s\" process dump \"%s\" stdinfo", selfname, resfile);
+    ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
+    wait_and_close_child_process(&info);
+    CloseHandle(startup.hStdInput);
+
+    reload_child_info(resfile);
+    /* handles values are available */
+    okChildInt("StartupInfoA", "hStdInput", (DWORD_PTR)startup.hStdInput);
+    okChildInt("StartupInfoA", "hStdOutput", (DWORD_PTR)startup.hStdOutput);
+    okChildInt("StartupInfoA", "hStdError", (DWORD_PTR)startup.hStdError);
+    okChildInt("StartupInfoW", "hStdInput", (DWORD_PTR)startup.hStdInput);
+    okChildInt("StartupInfoW", "hStdOutput", (DWORD_PTR)startup.hStdOutput);
+    okChildInt("StartupInfoW", "hStdError", (DWORD_PTR)startup.hStdError);
+    /* only inheritable objects are inherited */
+    okChildInt("StdHandleInfo", "hStdInput", HANDLE_FLAG_INHERIT);
+    ok(!isChildPresent("StdHandleInfo", "hStdOutput"), "hStdOutput shouldn't be present\n");
+    ok(!isChildPresent("StdHandleInfo", "hStdError"), "hStdError shouldn't be present\n");
+    release_memory();
+    DeleteFileA(resfile);
 }
 
 static  void    test_ExitCode(void)




More information about the wine-devel mailing list