Skip to content

Commit 472cf2f

Browse files
authored
[NTUSER][WIN32U_APITEST] Fix NtUserGetCursorInfo BSOD, add tests (reactos#8473)
Probe structure pointer before reading its cbSize. Also move the TRACE debug print outside the user critical region. CORE-18125
1 parent f1ef706 commit 472cf2f

4 files changed

Lines changed: 65 additions & 2 deletions

File tree

‎modules/rostests/apitests/win32u/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ list(APPEND SOURCE
5959
ntuser/NtUserFindExistingCursorIcon.c
6060
ntuser/NtUserGetAsyncKeyState.c
6161
ntuser/NtUserGetClassInfo.c
62+
ntuser/NtUserGetCursorInfo.c
6263
# ntuser/NtUserGetIconInfo.c
6364
ntuser/NtUserGetKeyboardLayoutName.c
6465
ntuser/NtUserGetThreadState.c
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* PROJECT: ReactOS API tests
3+
* LICENSE: MIT (https://spdx.org/licenses/MIT)
4+
* PURPOSE: Test for NtUserCreateAcceleratorTable
5+
* COPYRIGHT: Copyright 2025 Max Korostil <mrmks04@yandex.ru>
6+
*/
7+
8+
#include "../win32nt.h"
9+
10+
START_TEST(NtUserGetCursorInfo)
11+
{
12+
CURSORINFO cursor;
13+
DWORD error;
14+
BOOL res;
15+
16+
/* 1. NULL pointer */
17+
SetLastError(0);
18+
res = NtUserGetCursorInfo(NULL);
19+
error = GetLastError();
20+
21+
ok_int(res, FALSE);
22+
ok_int(error, ERROR_NOACCESS);
23+
24+
/* 2. Hardcoded invalid pointer */
25+
SetLastError(0);
26+
res = NtUserGetCursorInfo((PCURSORINFO)(ULONG_PTR)0xDEADBEEF);
27+
error = GetLastError();
28+
29+
ok_int(res, FALSE);
30+
ok_int(error, ERROR_NOACCESS);
31+
32+
/* 3. Invalid cbSize */
33+
SetLastError(0);
34+
cursor.cbSize = 0;
35+
res = NtUserGetCursorInfo(&cursor);
36+
error = GetLastError();
37+
38+
ok_int(res, FALSE);
39+
ok_int(error, ERROR_INVALID_PARAMETER);
40+
41+
/* 4. Single CURSORINFO pointer */
42+
SetLastError(0);
43+
cursor.cbSize = sizeof(cursor);
44+
res = NtUserGetCursorInfo(&cursor);
45+
error = GetLastError();
46+
47+
ok_int(res, TRUE);
48+
ok_int(error, ERROR_SUCCESS);
49+
50+
/* 5. Double CURSORINFO pointer */
51+
SetLastError(0);
52+
cursor.cbSize = sizeof(cursor) * 2;
53+
res = NtUserGetCursorInfo(&cursor);
54+
error = GetLastError();
55+
56+
ok_int(res, FALSE);
57+
ok_int(error, ERROR_INVALID_PARAMETER);
58+
}

‎modules/rostests/apitests/win32u/testlist.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extern void func_NtUserEnumDisplaySettings(void);
5454
extern void func_NtUserFindExistingCursorIcon(void);
5555
extern void func_NtUserGetAsyncKeyState(void);
5656
extern void func_NtUserGetClassInfo(void);
57+
extern void func_NtUserGetCursorInfo(void);
5758
//extern void func_NtUserGetIconInfo(void);
5859
extern void func_NtUserGetKeyboardLayoutName(void);
5960
extern void func_NtUserGetThreadState(void);
@@ -124,6 +125,7 @@ const struct test winetest_testlist[] =
124125
{ "NtUserFindExistingCursorIcon", func_NtUserFindExistingCursorIcon },
125126
{ "NtUserGetAsyncKeyState", func_NtUserGetAsyncKeyState },
126127
{ "NtUserGetClassInfo", func_NtUserGetClassInfo },
128+
{ "NtUserGetCursorInfo", func_NtUserGetCursorInfo },
127129
//{ "NtUserGetIconInfo", func_NtUserGetIconInfo },
128130
{ "NtUserGetKeyboardLayoutName", func_NtUserGetKeyboardLayoutName },
129131
{ "NtUserGetThreadState", func_NtUserGetThreadState },

‎win32ss/user/ntuser/cursoricon.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,10 @@ NtUserGetCursorInfo(
669669

670670
_SEH2_TRY
671671
{
672+
ProbeForWrite(pci, sizeof(CURSORINFO), 1);
673+
672674
if (pci->cbSize == sizeof(CURSORINFO))
673675
{
674-
ProbeForWrite(pci, sizeof(CURSORINFO), 1);
675676
RtlCopyMemory(pci, &SafeCi, sizeof(CURSORINFO));
676677
Ret = TRUE;
677678
}
@@ -690,8 +691,9 @@ NtUserGetCursorInfo(
690691
SetLastNtError(Status);
691692
}
692693

693-
TRACE("Leave NtUserGetCursorInfo, ret=%i\n", Ret);
694694
UserLeave();
695+
TRACE("Leave NtUserGetCursorInfo, ret=%i\n", Ret);
696+
695697
return Ret;
696698
}
697699

0 commit comments

Comments
 (0)