Jacek Caban : kernel32: Allow non-console handles in DuplicateConsoleHandle.

Alexandre Julliard julliard at winehq.org
Wed Nov 11 15:31:43 CST 2020


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Nov 11 20:06:39 2020 +0100

kernel32: Allow non-console handles in DuplicateConsoleHandle.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/console.c       | 10 +++-------
 dlls/kernel32/tests/console.c | 29 +++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c
index 4b74c1183ca..8d5f8181ffe 100644
--- a/dlls/kernel32/console.c
+++ b/dlls/kernel32/console.c
@@ -113,13 +113,9 @@ BOOL WINAPI VerifyConsoleIoHandle(HANDLE handle)
 HANDLE WINAPI DuplicateConsoleHandle(HANDLE handle, DWORD access, BOOL inherit,
                                      DWORD options)
 {
-    HANDLE      ret;
-
-    if (!is_console_handle(handle) ||
-        !DuplicateHandle(GetCurrentProcess(), wine_server_ptr_handle(console_handle_unmap(handle)),
-                         GetCurrentProcess(), &ret, access, inherit, options))
-        return INVALID_HANDLE_VALUE;
-    return console_handle_map(ret);
+    HANDLE ret;
+    return DuplicateHandle(GetCurrentProcess(), handle, GetCurrentProcess(), &ret,
+                           access, inherit, options) ? ret : INVALID_HANDLE_VALUE;
 }
 
 /******************************************************************
diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c
index 4a06a2b396e..69005bab5f1 100644
--- a/dlls/kernel32/tests/console.c
+++ b/dlls/kernel32/tests/console.c
@@ -1506,6 +1506,34 @@ static void test_GetSetStdHandle(void)
     ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
 }
 
+static void test_DuplicateConsoleHandle(void)
+{
+    HANDLE handle, event;
+    BOOL ret;
+
+    if (skip_nt) return;
+
+    event = CreateEventW(NULL, TRUE, FALSE, NULL);
+
+    /* duplicate an event handle with DuplicateConsoleHandle */
+    handle = DuplicateConsoleHandle(event, 0, FALSE, DUPLICATE_SAME_ACCESS);
+    ok(handle != NULL, "DuplicateConsoleHandle failed: %u\n", GetLastError());
+
+    ret = SetEvent(handle);
+    ok(ret, "SetEvent failed: %u\n", GetLastError());
+
+    ret = CloseConsoleHandle(handle);
+    todo_wine
+    ok(ret, "CloseConsoleHandle failed: %u\n", GetLastError());
+    ret = CloseConsoleHandle(event);
+    todo_wine
+    ok(ret, "CloseConsoleHandle failed: %u\n", GetLastError());
+
+    handle = DuplicateConsoleHandle((HANDLE)0xdeadbeef, 0, FALSE, DUPLICATE_SAME_ACCESS);
+    ok(handle == INVALID_HANDLE_VALUE, "DuplicateConsoleHandle failed: %u\n", GetLastError());
+    ok(GetLastError() == ERROR_INVALID_HANDLE, "last error = %u\n", GetLastError());
+}
+
 static void test_GetNumberOfConsoleInputEvents(HANDLE input_handle)
 {
     DWORD count;
@@ -4387,6 +4415,7 @@ START_TEST(console)
     test_OpenCON();
     test_VerifyConsoleIoHandle(hConOut);
     test_GetSetStdHandle();
+    test_DuplicateConsoleHandle();
     test_GetNumberOfConsoleInputEvents(hConIn);
     test_WriteConsoleInputA(hConIn);
     test_WriteConsoleInputW(hConIn);




More information about the wine-cvs mailing list