https://git.reactos.org/?p=reactos.git;a=commitdiff;h=885459d8b4327be84d009…
commit 885459d8b4327be84d009532688227f9c008975e
Author: Thomas Faber <thomas.faber(a)reactos.org>
AuthorDate: Sun Apr 10 18:29:10 2022 -0400
Commit: Thomas Faber <thomas.faber(a)reactos.org>
CommitDate: Sun Oct 30 10:46:33 2022 -0400
[WIN32K:NTUSER] Fix parameter check in NtUserGetAsyncKeyState. CORE-18124
---
modules/rostests/apitests/win32nt/CMakeLists.txt | 1 +
.../win32nt/ntuser/NtUserGetAsyncKeyState.c | 80 ++++++++++++++++++++++
modules/rostests/apitests/win32nt/testlist.c | 2 +
win32ss/user/ntuser/keyboard.c | 2 +-
4 files changed, 84 insertions(+), 1 deletion(-)
diff --git a/modules/rostests/apitests/win32nt/CMakeLists.txt
b/modules/rostests/apitests/win32nt/CMakeLists.txt
index 7060f79f219..a861830bbc0 100644
--- a/modules/rostests/apitests/win32nt/CMakeLists.txt
+++ b/modules/rostests/apitests/win32nt/CMakeLists.txt
@@ -52,6 +52,7 @@ list(APPEND SOURCE
# ntuser/NtUserEnumDisplayMonitors.c
ntuser/NtUserEnumDisplaySettings.c
ntuser/NtUserFindExistingCursorIcon.c
+ ntuser/NtUserGetAsyncKeyState.c
ntuser/NtUserGetClassInfo.c
# ntuser/NtUserGetIconInfo.c
ntuser/NtUserGetKeyboardLayoutName.c
diff --git a/modules/rostests/apitests/win32nt/ntuser/NtUserGetAsyncKeyState.c
b/modules/rostests/apitests/win32nt/ntuser/NtUserGetAsyncKeyState.c
new file mode 100644
index 00000000000..8e5e4cab544
--- /dev/null
+++ b/modules/rostests/apitests/win32nt/ntuser/NtUserGetAsyncKeyState.c
@@ -0,0 +1,80 @@
+/*
+ * PROJECT: ReactOS Win32k tests
+ * LICENSE: LGPL-2.1-or-later (
https://spdx.org/licenses/LGPL-2.1-or-later)
+ * PURPOSE: Test for NtUserGetAsyncKeyState
+ * COPYRIGHT: Copyright 2022 Thomas Faber (thomas.faber(a)reactos.org)
+ */
+
+#include <win32nt.h>
+
+START_TEST(NtUserGetAsyncKeyState)
+{
+ SHORT Ret;
+ DWORD Error;
+
+ SetLastError(0xdeadbeef);
+ Ret = NtUserGetAsyncKeyState(0);
+ Error = GetLastError();
+ ok(Ret == 0, "Ret = %d\n", Ret);
+ ok(Error == 0xdeadbeef, "Error = %lu\n", Error);
+
+ SetLastError(0xdeadbeef);
+ Ret = NtUserGetAsyncKeyState(1); // VK_LBUTTON
+ Error = GetLastError();
+ ok(Ret == 0 || Ret == 1, "Ret = %d\n", Ret);
+ ok(Error == 0xdeadbeef, "Error = %lu\n", Error);
+
+ SetLastError(0xdeadbeef);
+ Ret = NtUserGetAsyncKeyState(0xfe);
+ Error = GetLastError();
+ ok(Ret == 0, "Ret = %d\n", Ret);
+ ok(Error == 0xdeadbeef, "Error = %lu\n", Error);
+
+ SetLastError(0xdeadbeef);
+ Ret = NtUserGetAsyncKeyState(0xff);
+ Error = GetLastError();
+ ok(Ret == 0, "Ret = %d\n", Ret);
+ ok(Error == 0xdeadbeef, "Error = %lu\n", Error);
+
+ SetLastError(0xdeadbeef);
+ Ret = NtUserGetAsyncKeyState(0x100);
+ Error = GetLastError();
+ ok(Ret == 0, "Ret = %d\n", Ret);
+ ok(Error == ERROR_INVALID_PARAMETER, "Error = %lu\n", Error);
+
+ SetLastError(0xdeadbeef);
+ Ret = NtUserGetAsyncKeyState(0x101);
+ Error = GetLastError();
+ ok(Ret == 0, "Ret = %d\n", Ret);
+ ok(Error == ERROR_INVALID_PARAMETER, "Error = %lu\n", Error);
+
+ SetLastError(0xdeadbeef);
+ Ret = NtUserGetAsyncKeyState(0x10000000);
+ Error = GetLastError();
+ ok(Ret == 0, "Ret = %d\n", Ret);
+ ok(Error == ERROR_INVALID_PARAMETER, "Error = %lu\n", Error);
+
+ SetLastError(0xdeadbeef);
+ Ret = NtUserGetAsyncKeyState(0x7fffffff);
+ Error = GetLastError();
+ ok(Ret == 0, "Ret = %d\n", Ret);
+ ok(Error == ERROR_INVALID_PARAMETER, "Error = %lu\n", Error);
+
+ SetLastError(0xdeadbeef);
+ Ret = NtUserGetAsyncKeyState(0x80000000);
+ Error = GetLastError();
+ ok(Ret == 0, "Ret = %d\n", Ret);
+ ok(Error == ERROR_INVALID_PARAMETER, "Error = %lu\n", Error);
+
+ SetLastError(0xdeadbeef);
+ Ret = NtUserGetAsyncKeyState(-2);
+ Error = GetLastError();
+ ok(Ret == 0, "Ret = %d\n", Ret);
+ ok(Error == ERROR_INVALID_PARAMETER, "Error = %lu\n", Error);
+
+ SetLastError(0xdeadbeef);
+ Ret = NtUserGetAsyncKeyState(-1);
+ Error = GetLastError();
+ ok(Ret == 0, "Ret = %d\n", Ret);
+ ok(Error == ERROR_INVALID_PARAMETER, "Error = %lu\n", Error);
+}
diff --git a/modules/rostests/apitests/win32nt/testlist.c
b/modules/rostests/apitests/win32nt/testlist.c
index 8d2be31fc2c..c63cc42c101 100644
--- a/modules/rostests/apitests/win32nt/testlist.c
+++ b/modules/rostests/apitests/win32nt/testlist.c
@@ -52,6 +52,7 @@ extern void func_NtUserCreateWindowEx(void);
//extern void func_NtUserEnumDisplayMonitors(void);
extern void func_NtUserEnumDisplaySettings(void);
extern void func_NtUserFindExistingCursorIcon(void);
+extern void func_NtUserGetAsyncKeyState(void);
extern void func_NtUserGetClassInfo(void);
//extern void func_NtUserGetIconInfo(void);
extern void func_NtUserGetKeyboardLayoutName(void);
@@ -120,6 +121,7 @@ const struct test winetest_testlist[] =
//{ "NtUserEnumDisplayMonitors", func_NtUserEnumDisplayMonitors },
{ "NtUserEnumDisplaySettings", func_NtUserEnumDisplaySettings },
{ "NtUserFindExistingCursorIcon", func_NtUserFindExistingCursorIcon },
+ { "NtUserGetAsyncKeyState", func_NtUserGetAsyncKeyState },
{ "NtUserGetClassInfo", func_NtUserGetClassInfo },
//{ "NtUserGetIconInfo", func_NtUserGetIconInfo },
{ "NtUserGetKeyboardLayoutName", func_NtUserGetKeyboardLayoutName },
diff --git a/win32ss/user/ntuser/keyboard.c b/win32ss/user/ntuser/keyboard.c
index 3d427d1cb0b..61f59296be0 100644
--- a/win32ss/user/ntuser/keyboard.c
+++ b/win32ss/user/ntuser/keyboard.c
@@ -635,7 +635,7 @@ NtUserGetAsyncKeyState(INT Key)
TRACE("Enter NtUserGetAsyncKeyState\n");
- if (Key >= 0x100)
+ if (Key >= 0x100 || Key < 0)
{
EngSetLastError(ERROR_INVALID_PARAMETER);
ERR("Invalid parameter Key\n");