[PATCH] user32: Fail if an invalid window handle is passed to GetMessage().

Zebediah Figura z.figura12 at gmail.com
Tue Sep 10 18:45:18 CDT 2019


Fixes a hang when closing Windows Media Player 10.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/user32/message.c   |  8 +++++++-
 dlls/user32/tests/msg.c | 12 ++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/dlls/user32/message.c b/dlls/user32/message.c
index 860ceefc38d..b0ab5be902b 100644
--- a/dlls/user32/message.c
+++ b/dlls/user32/message.c
@@ -3836,6 +3836,12 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT
     HANDLE server_queue = get_server_queue_handle();
     unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE;  /* Always selected */
 
+    if (hwnd && !IsWindow( hwnd ))
+    {
+        SetLastError( ERROR_INVALID_WINDOW_HANDLE );
+        return -1;
+    }
+
     USER_CheckNotLock();
     check_for_driver_events( 0 );
 
@@ -3866,7 +3872,7 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT
 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
 {
     if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
-    GetMessageW( msg, hwnd, first, last );
+    if (GetMessageW( msg, hwnd, first, last ) == -1) return -1;
     map_wparam_WtoA( msg, TRUE );
     return (msg->message != WM_QUIT);
 }
diff --git a/dlls/user32/tests/msg.c b/dlls/user32/tests/msg.c
index 91d3fcc4846..aa5b89d15ec 100644
--- a/dlls/user32/tests/msg.c
+++ b/dlls/user32/tests/msg.c
@@ -17692,6 +17692,17 @@ static void test_SendMessage_pump(void)
     DestroyWindow(hwnd);
 }
 
+static void test_invalid_window(void)
+{
+    MSG msg;
+    BOOL ret;
+
+    SetLastError(0xdeadbeef);
+    ret = GetMessageA(&msg, (HWND)0xdeadbeef, 0, 0);
+    ok(ret == -1, "wrong ret %d\n", ret);
+    ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError());
+}
+
 static void init_funcs(void)
 {
     HMODULE hKernel32 = GetModuleHandleA("kernel32.dll");
@@ -17817,6 +17828,7 @@ START_TEST(msg)
     test_notify_message();
     test_SetActiveWindow();
     test_restore_messages();
+    test_invalid_window();
 
     if (!pTrackMouseEvent)
         win_skip("TrackMouseEvent is not available\n");
-- 
2.23.0




More information about the wine-devel mailing list