https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c2a51c7249804ab0f1736…
commit c2a51c7249804ab0f17367a0a9cce3f6387d8238
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Thu May 5 08:49:00 2022 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Thu May 5 08:49:00 2022 +0900
[NTUSER][USER32] Make NtUserBuildHwndList exclusive (#4485)
- Modify prototype of NtUserBuildHwndList function.
- Wrap the code by UserEnterExclusive(); and UserLeave();.
CORE-18173
---
win32ss/include/ntuser.h | 6 ++---
win32ss/user/ntuser/window.c | 51 +++++++++++++++++++++---------------
win32ss/user/user32/windows/mdi.c | 4 +--
win32ss/user/user32/windows/window.c | 4 +--
4 files changed, 37 insertions(+), 28 deletions(-)
diff --git a/win32ss/include/ntuser.h b/win32ss/include/ntuser.h
index 0eea35fffa4..68999e7f932 100644
--- a/win32ss/include/ntuser.h
+++ b/win32ss/include/ntuser.h
@@ -1561,9 +1561,9 @@ NtUserBuildHwndList(
HWND hwndParent,
BOOLEAN bChildren,
ULONG dwThreadId,
- ULONG lParam,
- HWND *pWnd,
- ULONG *pBufSize);
+ ULONG cHwnd,
+ HWND *phwndList,
+ ULONG *pcHwndNeeded);
NTSTATUS
NTAPI
diff --git a/win32ss/user/ntuser/window.c b/win32ss/user/ntuser/window.c
index cc34e5e6256..5f588406bdd 100644
--- a/win32ss/user/ntuser/window.c
+++ b/win32ss/user/ntuser/window.c
@@ -1500,22 +1500,24 @@ VOID FASTCALL IntFreeHwndList(PWINDOWLIST pwlTarget)
* @implemented
*/
NTSTATUS
-APIENTRY
+NTAPI
NtUserBuildHwndList(
HDESK hDesktop,
HWND hwndParent,
BOOLEAN bChildren,
ULONG dwThreadId,
- ULONG lParam,
- HWND* pWnd,
- ULONG* pBufSize)
+ ULONG cHwnd,
+ HWND* phwndList,
+ ULONG* pcHwndNeeded)
{
NTSTATUS Status;
ULONG dwCount = 0;
- if (pBufSize == 0)
+ if (pcHwndNeeded == NULL)
return ERROR_INVALID_PARAMETER;
+ UserEnterExclusive();
+
if (hwndParent || !dwThreadId)
{
PDESKTOP Desktop;
@@ -1525,7 +1527,8 @@ NtUserBuildHwndList(
{
if(hDesktop == NULL && !(Desktop = IntGetActiveDesktop()))
{
- return ERROR_INVALID_HANDLE;
+ Status = ERROR_INVALID_HANDLE;
+ goto Quit;
}
if(hDesktop)
@@ -1536,7 +1539,8 @@ NtUserBuildHwndList(
&Desktop);
if(!NT_SUCCESS(Status))
{
- return ERROR_INVALID_HANDLE;
+ Status = ERROR_INVALID_HANDLE;
+ goto Quit;
}
}
hwndParent = Desktop->DesktopWindow;
@@ -1556,13 +1560,13 @@ NtUserBuildHwndList(
{
if (bGoDown)
{
- if(dwCount++ < *pBufSize && pWnd)
+ if (dwCount++ < cHwnd && phwndList)
{
_SEH2_TRY
{
- ProbeForWrite(pWnd, sizeof(HWND), 1);
- *pWnd = Window->head.h;
- pWnd++;
+ ProbeForWrite(phwndList, sizeof(HWND), 1);
+ *phwndList = Window->head.h;
+ phwndList++;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
@@ -1571,7 +1575,6 @@ NtUserBuildHwndList(
_SEH2_END
if(!NT_SUCCESS(Status))
{
- SetLastNtError(Status);
break;
}
}
@@ -1612,13 +1615,15 @@ NtUserBuildHwndList(
if (!NT_SUCCESS(Status))
{
ERR("Thread Id is not valid!\n");
- return ERROR_INVALID_PARAMETER;
+ Status = ERROR_INVALID_PARAMETER;
+ goto Quit;
}
if (!(W32Thread = (PTHREADINFO)Thread->Tcb.Win32Thread))
{
ObDereferenceObject(Thread);
TRACE("Tried to enumerate windows of a non gui thread\n");
- return ERROR_INVALID_PARAMETER;
+ Status = ERROR_INVALID_PARAMETER;
+ goto Quit;
}
// Do not use Thread link list due to co_UserFreeWindow!!!
@@ -1633,13 +1638,13 @@ NtUserBuildHwndList(
Window = ValidateHwndNoErr(List[i]);
if (Window && Window->head.pti == W32Thread)
{
- if (dwCount < *pBufSize && pWnd)
+ if (dwCount < cHwnd && phwndList)
{
_SEH2_TRY
{
- ProbeForWrite(pWnd, sizeof(HWND), 1);
- *pWnd = Window->head.h;
- pWnd++;
+ ProbeForWrite(phwndList, sizeof(HWND), 1);
+ *phwndList = Window->head.h;
+ phwndList++;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
@@ -1649,7 +1654,6 @@ NtUserBuildHwndList(
if (!NT_SUCCESS(Status))
{
ERR("Failure to build window list!\n");
- SetLastNtError(Status);
break;
}
}
@@ -1662,8 +1666,13 @@ NtUserBuildHwndList(
ObDereferenceObject(Thread);
}
- *pBufSize = dwCount;
- return STATUS_SUCCESS;
+ *pcHwndNeeded = dwCount;
+ Status = STATUS_SUCCESS;
+
+Quit:
+ SetLastNtError(Status);
+ UserLeave();
+ return Status;
}
static void IntSendParentNotify( PWND pWindow, UINT msg )
diff --git a/win32ss/user/user32/windows/mdi.c b/win32ss/user/user32/windows/mdi.c
index 59a3d06c506..9424b4cfe6e 100644
--- a/win32ss/user/user32/windows/mdi.c
+++ b/win32ss/user/user32/windows/mdi.c
@@ -145,7 +145,7 @@ HWND* WIN_ListChildren (HWND hWndparent)
HANDLE hHeap;
NTSTATUS Status;
- Status = NtUserBuildHwndList ( NULL, hWndparent, FALSE, 0, 0, NULL, &dwCount );
+ Status = NtUserBuildHwndList(NULL, hWndparent, FALSE, 0, dwCount, NULL, &dwCount);
if ( !NT_SUCCESS( Status ) )
return 0;
@@ -161,7 +161,7 @@ HWND* WIN_ListChildren (HWND hWndparent)
}
/* now call kernel again to fill the buffer this time */
- Status = NtUserBuildHwndList (NULL, hWndparent, FALSE, 0, 0, pHwnd, &dwCount );
+ Status = NtUserBuildHwndList(NULL, hWndparent, FALSE, 0, dwCount, pHwnd,
&dwCount);
if ( !NT_SUCCESS( Status ) )
{
diff --git a/win32ss/user/user32/windows/window.c b/win32ss/user/user32/windows/window.c
index 0946c5b68ca..93dd53358c5 100644
--- a/win32ss/user/user32/windows/window.c
+++ b/win32ss/user/user32/windows/window.c
@@ -701,7 +701,7 @@ User32EnumWindows(HDESK hDesktop,
hWndparent,
bChildren,
dwThreadId,
- lParam,
+ dwCount,
NULL,
&dwCount);
if (!NT_SUCCESS(Status))
@@ -729,7 +729,7 @@ User32EnumWindows(HDESK hDesktop,
hWndparent,
bChildren,
dwThreadId,
- lParam,
+ dwCount,
pHwnd,
&dwCount);
if (!NT_SUCCESS(Status))