From 30554d4ef12038e07961b16013c5dacb0fca3503 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 16 Nov 2010 20:57:27 +0100 Subject: [PATCH] user32: Check structure size in GetGUIThreadInfo. --- dlls/user32/focus.c | 1 + dlls/user32/message.c | 7 +++++++ dlls/user32/painting.c | 1 + dlls/user32/tests/win.c | 16 ++++++++++++++++ dlls/user32/win.c | 1 + dlls/winex11.drv/event.c | 1 + 6 files changed, 27 insertions(+) diff --git a/dlls/user32/focus.c b/dlls/user32/focus.c index f0865841077..70a2a8a6f5b 100644 --- a/dlls/user32/focus.c +++ b/dlls/user32/focus.c @@ -160,6 +160,7 @@ static BOOL set_active_window( HWND hwnd, HWND *prev, BOOL mouse, BOOL focus ) { GUITHREADINFO info; + info.cbSize = sizeof(info); GetGUIThreadInfo( GetCurrentThreadId(), &info ); /* Do not change focus if the window is no more active */ if (hwnd == info.hwndActive) diff --git a/dlls/user32/message.c b/dlls/user32/message.c index b073e1c44ba..c6daf319130 100644 --- a/dlls/user32/message.c +++ b/dlls/user32/message.c @@ -2359,6 +2359,7 @@ static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, H /* find the window to dispatch this mouse message to */ + info.cbSize = sizeof(info); GetGUIThreadInfo( GetCurrentThreadId(), &info ); if (info.hwndCapture) { @@ -4235,6 +4236,12 @@ BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info ) { BOOL ret; + if (info->cbSize != sizeof(*info)) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } + SERVER_START_REQ( get_thread_input ) { req->tid = id; diff --git a/dlls/user32/painting.c b/dlls/user32/painting.c index e7ce2ec6b89..c3a25fb1007 100644 --- a/dlls/user32/painting.c +++ b/dlls/user32/painting.c @@ -801,6 +801,7 @@ static HWND fix_caret(HWND hWnd, const RECT *scroll_rect, INT dx, INT dy, RECT rect, mapped_rcCaret; BOOL hide_caret = FALSE; + info.cbSize = sizeof(info); if (!GetGUIThreadInfo( GetCurrentThreadId(), &info )) return 0; if (!info.hwndCaret) return 0; diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index 5a378de70c3..ab066872e60 100644 --- a/dlls/user32/tests/win.c +++ b/dlls/user32/tests/win.c @@ -611,6 +611,22 @@ static DWORD CALLBACK enum_thread( void *arg ) BOOL ret; MSG msg; + if (pGetGUIThreadInfo) + { + GUITHREADINFO info; + info.cbSize = sizeof(info); + ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info ); + ok( ret || broken(!ret), /* win9x */ + "GetGUIThreadInfo failed without message queue\n" ); + SetLastError( 0xdeadbeef ); + info.cbSize = sizeof(info) + 1; + ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info ); + ok( !ret, "GetGUIThreadInfo succeeded with wrong size\n" ); + ok( GetLastError() == ERROR_INVALID_PARAMETER || + broken(GetLastError() == 0xdeadbeef), /* win9x */ + "wrong error %u\n", GetLastError() ); + } + PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */ count = 0; diff --git a/dlls/user32/win.c b/dlls/user32/win.c index f9b6be2f7c2..f1da48b45b6 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -1587,6 +1587,7 @@ static void WIN_SendDestroyMsg( HWND hwnd ) { GUITHREADINFO info; + info.cbSize = sizeof(info); if (GetGUIThreadInfo( GetCurrentThreadId(), &info )) { if (hwnd == info.hwndCaret) DestroyCaret(); diff --git a/dlls/winex11.drv/event.c b/dlls/winex11.drv/event.c index ae0875bc1d0..5447a40ecf2 100644 --- a/dlls/winex11.drv/event.c +++ b/dlls/winex11.drv/event.c @@ -497,6 +497,7 @@ static void set_focus( Display *display, HWND hwnd, Time time ) TRACE( "setting foreground window to %p\n", hwnd ); SetForegroundWindow( hwnd ); + threadinfo.cbSize = sizeof(threadinfo); GetGUIThreadInfo(0, &threadinfo); focus = threadinfo.hwndFocus; if (!focus) focus = threadinfo.hwndActive; -- 2.11.4.GIT