diff --git a/win32ss/user/ntuser/winpos.c b/win32ss/user/ntuser/winpos.c index 2e5822994f3..227b03e8a5c 100644 --- a/win32ss/user/ntuser/winpos.c +++ b/win32ss/user/ntuser/winpos.c @@ -553,7 +553,6 @@ WinPosInitInternalPos(PWND Wnd, RECTL *RestoreRect) } } -// Win: _GetWindowPlacement BOOL FASTCALL IntGetWindowPlacement(PWND Wnd, WINDOWPLACEMENT *lpwndpl) @@ -562,6 +561,7 @@ IntGetWindowPlacement(PWND Wnd, WINDOWPLACEMENT *lpwndpl) if(lpwndpl->length != sizeof(WINDOWPLACEMENT)) { + ERR("length mismatch: %u\n", lpwndpl->length); return FALSE; } @@ -3398,9 +3398,7 @@ NtUserGetWindowPlacement(HWND hWnd, UserEnterShared(); if (!(Wnd = UserGetWindowObject(hWnd))) - { goto Exit; // Return FALSE - } Status = MmCopyFromCaller(&Safepl, lpwndpl, sizeof(WINDOWPLACEMENT)); if (!NT_SUCCESS(Status)) @@ -3409,6 +3407,7 @@ NtUserGetWindowPlacement(HWND hWnd, goto Exit; // Return FALSE } + // This function doesn't check the length. Just overwrite it Safepl.length = sizeof(WINDOWPLACEMENT); IntGetWindowPlacement(Wnd, &Safepl); @@ -3709,35 +3708,40 @@ NtUserSetWindowPlacement(HWND hWnd, TRACE("Enter NtUserSetWindowPlacement\n"); UserEnterExclusive(); - if (!(Wnd = UserGetWindowObject(hWnd)) || - UserIsDesktopWindow(Wnd) || UserIsMessageWindow(Wnd)) - { - goto Exit; // Return FALSE - } + _SEH2_TRY + { + ProbeForRead(lpwndpl, sizeof(*lpwndpl), 1); + Safepl = *lpwndpl; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastNtError(_SEH2_GetExceptionCode()); + _SEH2_YIELD(goto Exit); // Return FALSE + } + _SEH2_END - _SEH2_TRY - { - ProbeForRead(lpwndpl, sizeof(WINDOWPLACEMENT), 1); - RtlCopyMemory(&Safepl, lpwndpl, sizeof(WINDOWPLACEMENT)); - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - SetLastNtError(_SEH2_GetExceptionCode()); - _SEH2_YIELD(goto Exit); // Return FALSE - } - _SEH2_END + /* Backwards-compatibility: Win 3.x doesn't check the length */ + if (LOWORD(gptiCurrent->dwExpWinVer) < WINVER_WINNT4) + Safepl.length = sizeof(Safepl); - if(Safepl.length != sizeof(WINDOWPLACEMENT)) - { - goto Exit; // Return FALSE - } + if (Safepl.length != sizeof(Safepl)) + { + EngSetLastError(ERROR_INVALID_PARAMETER); + goto Exit; + } - Flags = PLACE_MAX | PLACE_RECT; - if (Safepl.flags & WPF_SETMINPOSITION) Flags |= PLACE_MIN; - UserRefObjectCo(Wnd, &Ref); - IntSetWindowPlacement(Wnd, &Safepl, Flags); - UserDerefObjectCo(Wnd); - Ret = TRUE; + Flags = PLACE_MAX | PLACE_RECT; + if (Safepl.flags & WPF_SETMINPOSITION) + Flags |= PLACE_MIN; + + Wnd = UserGetWindowObject(hWnd); + if (!Wnd) + goto Exit; // Return FALSE + + UserRefObjectCo(Wnd, &Ref); + if (!UserIsDesktopWindow(Wnd) && !UserIsMessageWindow(Wnd)) + Ret = IntSetWindowPlacement(Wnd, &Safepl, Flags); + UserDerefObjectCo(Wnd); Exit: TRACE("Leave NtUserSetWindowPlacement, ret=%i\n", Ret);