From 5e65b65219bd56a5991c2c54df99b524e379846a Mon Sep 17 00:00:00 2001 From: Rodrigo Rivas Costa Date: Sat, 9 Apr 2016 09:09:20 +0300 Subject: [PATCH] user32: Make DeferWindowPos() fail on invalid window handles. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/user32/tests/win.c | 35 +++++++++++++++++++++++++++++++++++ dlls/user32/winpos.c | 6 +++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index 957e8a1d07d..918e1ef522d 100644 --- a/dlls/user32/tests/win.c +++ b/dlls/user32/tests/win.c @@ -8821,6 +8821,40 @@ static void test_winproc_limit(void) ok(i == 1, "winproc should be called once (%d)\n", i); } +static void test_deferwindowpos(void) +{ + HDWP hdwp, hdwp2; + BOOL ret; + + hdwp = BeginDeferWindowPos(0); + ok(hdwp != NULL, "got %p\n", hdwp); + + ret = EndDeferWindowPos(NULL); + ok(!ret, "got %d\n", ret); + + hdwp2 = DeferWindowPos(NULL, NULL, NULL, 0, 0, 10, 10, 0); +todo_wine + ok(hdwp2 == NULL && ((GetLastError() == ERROR_INVALID_DWP_HANDLE) || + broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE) /* before win8 */), "got %p, error %d\n", hdwp2, GetLastError()); + + hdwp2 = DeferWindowPos((HDWP)0xdead, GetDesktopWindow(), NULL, 0, 0, 10, 10, 0); +todo_wine + ok(hdwp2 == NULL && ((GetLastError() == ERROR_INVALID_DWP_HANDLE) || + broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE) /* before win8 */), "got %p, error %d\n", hdwp2, GetLastError()); + + hdwp2 = DeferWindowPos(hdwp, NULL, NULL, 0, 0, 10, 10, 0); + ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError()); + + hdwp2 = DeferWindowPos(hdwp, GetDesktopWindow(), NULL, 0, 0, 10, 10, 0); + ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError()); + + hdwp2 = DeferWindowPos(hdwp, (HWND)0xdead, NULL, 0, 0, 10, 10, 0); + ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError()); + + ret = EndDeferWindowPos(hdwp); + ok(ret, "got %d\n", ret); +} + START_TEST(win) { char **argv; @@ -8963,6 +8997,7 @@ START_TEST(win) test_GetMessagePos(); test_activateapp(hwndMain); test_winproc_handles(argv[0]); + test_deferwindowpos(); /* add the tests above this line */ if (hhook) UnhookWindowsHookEx(hhook); diff --git a/dlls/user32/winpos.c b/dlls/user32/winpos.c index f92a3dced2c..4915aadc48f 100644 --- a/dlls/user32/winpos.c +++ b/dlls/user32/winpos.c @@ -2348,7 +2348,11 @@ HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter, hdwp, hwnd, hwndAfter, x, y, cx, cy, flags); hwnd = WIN_GetFullHandle( hwnd ); - if (is_desktop_window( hwnd )) return 0; + if (is_desktop_window( hwnd ) || !IsWindow( hwnd )) + { + SetLastError( ERROR_INVALID_WINDOW_HANDLE ); + return 0; + } if (!(pDWP = get_user_handle_ptr( hdwp, USER_DWP ))) return 0; if (pDWP == OBJ_OTHER_PROCESS)