[PATCH] ntdll: Tolerate null handle in DeregisterWait

Keno Fischer keno at juliacomputing.com
Thu Aug 18 15:17:49 CDT 2016


Noticed in libuv, which is not particularly careful about whether or not
the handle it's passing to UnregisterWait is valid or NULL. Windows
has an explicit NULL check here and returns ERROR_INVALID_HANDLE.

Fixes https://github.com/JuliaLang/julia/issues/18070.

Signed-off-by: Keno Fischer <keno at juliacomputing.com>
---
 dlls/kernel32/tests/thread.c | 5 +++++
 dlls/ntdll/threadpool.c      | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/dlls/kernel32/tests/thread.c b/dlls/kernel32/tests/thread.c
index b5ad1da..a6f684e 100644
--- a/dlls/kernel32/tests/thread.c
+++ b/dlls/kernel32/tests/thread.c
@@ -1245,6 +1245,11 @@ static void test_RegisterWaitForSingleObject(void)

     ret = pUnregisterWait(wait_handle);
     ok(ret, "UnregisterWait failed with error %d\n", GetLastError());
+
+    /* Test UnregisterWait null argument case */
+    ret = pUnregisterWait(0);
+    ok(!ret && GetLastError() == ERROR_INVALID_HANDLE,
+        "UnregisterWait failed with unexpected error %d\n", GetLastError());
 }

 static DWORD TLS_main;
diff --git a/dlls/ntdll/threadpool.c b/dlls/ntdll/threadpool.c
index 799245c..9ff0122 100644
--- a/dlls/ntdll/threadpool.c
+++ b/dlls/ntdll/threadpool.c
@@ -637,6 +637,9 @@ NTSTATUS WINAPI RtlDeregisterWaitEx(HANDLE
WaitHandle, HANDLE CompletionEvent)

     TRACE( "(%p)\n", WaitHandle );

+    if (WaitHandle == NULL)
+        return STATUS_INVALID_HANDLE;
+
     NtSetEvent( wait_work_item->CancelEvent, NULL );
     if (wait_work_item->CallbackInProgress)
     {
-- 
2.7.4



More information about the wine-patches mailing list