Commit 1335768f authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

kernel32: Allow non-console handles in DuplicateConsoleHandle.

parent e460b37a
...@@ -113,13 +113,9 @@ BOOL WINAPI VerifyConsoleIoHandle(HANDLE handle) ...@@ -113,13 +113,9 @@ BOOL WINAPI VerifyConsoleIoHandle(HANDLE handle)
HANDLE WINAPI DuplicateConsoleHandle(HANDLE handle, DWORD access, BOOL inherit, HANDLE WINAPI DuplicateConsoleHandle(HANDLE handle, DWORD access, BOOL inherit,
DWORD options) DWORD options)
{ {
HANDLE ret; HANDLE ret;
return DuplicateHandle(GetCurrentProcess(), handle, GetCurrentProcess(), &ret,
if (!is_console_handle(handle) || access, inherit, options) ? ret : INVALID_HANDLE_VALUE;
!DuplicateHandle(GetCurrentProcess(), wine_server_ptr_handle(console_handle_unmap(handle)),
GetCurrentProcess(), &ret, access, inherit, options))
return INVALID_HANDLE_VALUE;
return console_handle_map(ret);
} }
/****************************************************************** /******************************************************************
......
...@@ -1506,6 +1506,34 @@ static void test_GetSetStdHandle(void) ...@@ -1506,6 +1506,34 @@ static void test_GetSetStdHandle(void)
ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error); 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) static void test_GetNumberOfConsoleInputEvents(HANDLE input_handle)
{ {
DWORD count; DWORD count;
...@@ -4387,6 +4415,7 @@ START_TEST(console) ...@@ -4387,6 +4415,7 @@ START_TEST(console)
test_OpenCON(); test_OpenCON();
test_VerifyConsoleIoHandle(hConOut); test_VerifyConsoleIoHandle(hConOut);
test_GetSetStdHandle(); test_GetSetStdHandle();
test_DuplicateConsoleHandle();
test_GetNumberOfConsoleInputEvents(hConIn); test_GetNumberOfConsoleInputEvents(hConIn);
test_WriteConsoleInputA(hConIn); test_WriteConsoleInputA(hConIn);
test_WriteConsoleInputW(hConIn); test_WriteConsoleInputW(hConIn);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment