[PATCH] user32: Check input to GetAsyncKeyState().

Lei Zhang thestig at google.com
Mon Dec 8 13:28:15 CST 2008


Hi,

Bad input to GetAsyncKeyState() should not cause a crash. This fixes bug 16345.
-------------- next part --------------
From 11409726c066a1a1c126c419a04f62fb31bb4e33 Mon Sep 17 00:00:00 2001
From: Lei Zhang <thestig at google.com>
Date: Mon, 8 Dec 2008 11:25:30 -0800
Subject: [PATCH] user32: Check input to GetAsyncKeyState().

---
 dlls/user32/input.c       |    2 ++
 dlls/user32/tests/input.c |    8 ++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/dlls/user32/input.c b/dlls/user32/input.c
index dce50b5..cefb24c 100644
--- a/dlls/user32/input.c
+++ b/dlls/user32/input.c
@@ -272,6 +272,8 @@ HWND WINAPI GetCapture(void)
  */
 SHORT WINAPI GetAsyncKeyState(INT nKey)
 {
+    if (nKey < 0 || nKey > 256)
+        return 0;
     return USER_Driver->pGetAsyncKeyState( nKey );
 }
 
diff --git a/dlls/user32/tests/input.c b/dlls/user32/tests/input.c
index 8211cdb..a242fba 100644
--- a/dlls/user32/tests/input.c
+++ b/dlls/user32/tests/input.c
@@ -1240,6 +1240,13 @@ static void test_ToUnicode(void)
     todo_wine ok(ret == 0, "ToUnicode for CTRL + SHIFT + Return didn't return 0 (was %i)\n", ret);
 }
 
+static void test_get_async_key_state(void)
+{
+    /* input value sanity checks */
+    ok(0 == GetAsyncKeyState(1000000), "GetAsyncKeyState did not return 0\n");
+    ok(0 == GetAsyncKeyState(-1000000), "GetAsyncKeyState did not return 0\n");
+}
+
 START_TEST(input)
 {
     init_function_pointers();
@@ -1254,6 +1261,7 @@ START_TEST(input)
     test_mouse_ll_hook();
     test_key_map();
     test_ToUnicode();
+    test_get_async_key_state();
 
     if(pGetMouseMovePointsEx)
         test_GetMouseMovePointsEx();
-- 
1.5.4.5


More information about the wine-patches mailing list