Hans Leidekker : imm32: Validate the window handle passed to ImmGetContext.

Alexandre Julliard julliard at winehq.org
Wed Nov 9 13:29:42 CST 2011


Module: wine
Branch: master
Commit: 21a477e161589630ed94e5561a595c63155e0e8f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=21a477e161589630ed94e5561a595c63155e0e8f

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Wed Nov  9 15:06:49 2011 +0100

imm32: Validate the window handle passed to ImmGetContext.

---

 dlls/imm32/imm.c         |    8 +++++++-
 dlls/imm32/tests/imm32.c |   17 +++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/dlls/imm32/imm.c b/dlls/imm32/imm.c
index a8392ff..decdcae 100644
--- a/dlls/imm32/imm.c
+++ b/dlls/imm32/imm.c
@@ -1360,9 +1360,15 @@ BOOL WINAPI ImmGetCompositionWindow(HIMC hIMC, LPCOMPOSITIONFORM lpCompForm)
  */
 HIMC WINAPI ImmGetContext(HWND hWnd)
 {
-    HIMC rc = NULL;
+    HIMC rc;
 
     TRACE("%p\n", hWnd);
+
+    if (!IsWindow(hWnd))
+    {
+        SetLastError(ERROR_INVALID_WINDOW_HANDLE);
+        return NULL;
+    }
     if (!IMM_GetThreadData()->defaultContext)
         IMM_GetThreadData()->defaultContext = ImmCreateContext();
 
diff --git a/dlls/imm32/tests/imm32.c b/dlls/imm32/tests/imm32.c
index 39bedb2..eca4d5e 100644
--- a/dlls/imm32/tests/imm32.c
+++ b/dlls/imm32/tests/imm32.c
@@ -557,6 +557,22 @@ static void test_ImmIsUIMessage(void)
     }
 }
 
+static void test_ImmGetContext(void)
+{
+    HIMC himc;
+    DWORD err;
+
+    SetLastError(0xdeadbeef);
+    himc = ImmGetContext((HWND)0xffffffff);
+    err = GetLastError();
+    ok(himc == NULL, "ImmGetContext succeeded\n");
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "got %u\n", err);
+
+    himc = ImmGetContext(hwnd);
+    ok(himc != NULL, "ImmGetContext failed\n");
+    ok(ImmReleaseContext(hwnd, himc), "ImmReleaseContext failed\n");
+}
+
 START_TEST(imm32) {
     if (init())
     {
@@ -567,6 +583,7 @@ START_TEST(imm32) {
         test_ImmAssociateContextEx();
         test_ImmThreads();
         test_ImmIsUIMessage();
+        test_ImmGetContext();
     }
     cleanup();
 }




More information about the wine-cvs mailing list