https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b0b925d2b071e9a1ad94a…
commit b0b925d2b071e9a1ad94a51d71f11bb71599fb0c
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sat Apr 23 08:16:53 2022 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Apr 23 08:16:53 2022 +0900
[IMM32] Add ValidateHandle function (#4467)
Set the last error on failure of handle validation.
CORE-11700
---
dll/win32/imm32/ime.c | 4 ++--
dll/win32/imm32/imm.c | 12 ++++++------
dll/win32/imm32/keymsg.c | 2 +-
dll/win32/imm32/precomp.h | 4 +++-
dll/win32/imm32/utils.c | 18 +++++++++++-------
5 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/dll/win32/imm32/ime.c b/dll/win32/imm32/ime.c
index e9c80d195b5..a13f59dd498 100644
--- a/dll/win32/imm32/ime.c
+++ b/dll/win32/imm32/ime.c
@@ -1692,7 +1692,7 @@ BOOL WINAPI ImmConfigureIMEA(HKL hKL, HWND hWnd, DWORD dwMode,
LPVOID lpData)
TRACE("(%p, %p, 0x%lX, %p)", hKL, hWnd, dwMode, lpData);
- if (!ValidateHwndNoErr(hWnd) || Imm32IsCrossProcessAccess(hWnd))
+ if (!ValidateHwnd(hWnd) || Imm32IsCrossProcessAccess(hWnd))
return FALSE;
pImeDpi = Imm32FindOrLoadImeDpi(hKL);
@@ -1746,7 +1746,7 @@ BOOL WINAPI ImmConfigureIMEW(HKL hKL, HWND hWnd, DWORD dwMode,
LPVOID lpData)
TRACE("(%p, %p, 0x%lX, %p)", hKL, hWnd, dwMode, lpData);
- if (!ValidateHwndNoErr(hWnd) || Imm32IsCrossProcessAccess(hWnd))
+ if (!ValidateHwnd(hWnd) || Imm32IsCrossProcessAccess(hWnd))
return FALSE;
pImeDpi = Imm32FindOrLoadImeDpi(hKL);
diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c
index 45328abb595..e2e1e639689 100644
--- a/dll/win32/imm32/imm.c
+++ b/dll/win32/imm32/imm.c
@@ -509,7 +509,7 @@ HIMC WINAPI ImmAssociateContext(HWND hWnd, HIMC hIMC)
if (!IS_IMM_MODE())
return NULL;
- pWnd = ValidateHwndNoErr(hWnd);
+ pWnd = ValidateHwnd(hWnd);
if (!pWnd)
return NULL;
@@ -555,7 +555,7 @@ BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD
dwFlags)
return FALSE;
hwndFocus = (HWND)NtUserQueryWindow(hWnd, QUERY_WINDOW_FOCUS);
- pFocusWnd = ValidateHwndNoErr(hwndFocus);
+ pFocusWnd = ValidateHwnd(hwndFocus);
if (pFocusWnd)
hOldIMC = pFocusWnd->hImc;
@@ -566,7 +566,7 @@ BOOL WINAPI ImmAssociateContextEx(HWND hWnd, HIMC hIMC, DWORD
dwFlags)
return TRUE;
case 1:
- pFocusWnd = ValidateHwndNoErr(hwndFocus);
+ pFocusWnd = ValidateHwnd(hwndFocus);
if (pFocusWnd)
{
hIMC = pFocusWnd->hImc;
@@ -647,7 +647,7 @@ BOOL APIENTRY Imm32DestroyInputContext(HIMC hIMC, HKL hKL, BOOL
bKeep)
if (!hIMC || !IS_IMM_MODE())
return FALSE;
- pIMC = ValidateHandleNoErr(hIMC, TYPE_INPUTCONTEXT);
+ pIMC = ValidateHandle(hIMC, TYPE_INPUTCONTEXT);
if (!pIMC || pIMC->head.pti != Imm32CurrentPti())
{
ERR("invalid pIMC: %p\n", pIMC);
@@ -916,7 +916,7 @@ PCLIENTIMC WINAPI ImmLockClientImc(HIMC hImc)
if (!hImc)
return NULL;
- pIMC = ValidateHandleNoErr(hImc, TYPE_INPUTCONTEXT);
+ pIMC = ValidateHandle(hImc, TYPE_INPUTCONTEXT);
if (!pIMC || !Imm32CheckImcProcess(pIMC))
return NULL;
@@ -986,7 +986,7 @@ static HIMC APIENTRY ImmGetSaveContext(HWND hWnd, DWORD
dwContextFlags)
goto Quit;
}
- pWnd = ValidateHwndNoErr(hWnd);
+ pWnd = ValidateHwnd(hWnd);
if (!pWnd || Imm32IsCrossProcessAccess(hWnd))
return NULL;
diff --git a/dll/win32/imm32/keymsg.c b/dll/win32/imm32/keymsg.c
index 684e4a762bc..2101fcb9afb 100644
--- a/dll/win32/imm32/keymsg.c
+++ b/dll/win32/imm32/keymsg.c
@@ -574,7 +574,7 @@ LRESULT APIENTRY ImmRequestMessageAW(HIMC hIMC, WPARAM wParam, LPARAM
lParam, BO
hWnd = pIC->hWnd;
if (hWnd)
- pWnd = ValidateHwndNoErr(hWnd);
+ pWnd = ValidateHwnd(hWnd);
if (pWnd && pWnd->head.pti == Imm32CurrentPti())
ret = Imm32ProcessRequest(hIMC, pWnd, (DWORD)wParam, (LPVOID)lParam, bAnsi);
diff --git a/dll/win32/imm32/precomp.h b/dll/win32/imm32/precomp.h
index 82af0034e9b..a7057be1a73 100644
--- a/dll/win32/imm32/precomp.h
+++ b/dll/win32/imm32/precomp.h
@@ -79,8 +79,10 @@ extern HANDLE ghImmHeap;
BOOL Imm32GetSystemLibraryPath(LPWSTR pszPath, DWORD cchPath, LPCWSTR pszFileName);
VOID APIENTRY LogFontAnsiToWide(const LOGFONTA *plfA, LPLOGFONTW plfW);
VOID APIENTRY LogFontWideToAnsi(const LOGFONTW *plfW, LPLOGFONTA plfA);
-PWND FASTCALL ValidateHwndNoErr(HWND hwnd);
LPVOID FASTCALL ValidateHandleNoErr(HANDLE hObject, UINT uType);
+LPVOID FASTCALL ValidateHandle(HANDLE hObject, UINT uType);
+#define ValidateHwndNoErr(hwnd) ValidateHandleNoErr((hwnd), TYPE_WINDOW)
+#define ValidateHwnd(hwnd) ValidateHandle((hwnd), TYPE_WINDOW)
BOOL APIENTRY Imm32CheckImcProcess(PIMC pIMC);
LPVOID APIENTRY ImmLocalAlloc(DWORD dwFlags, DWORD dwBytes);
diff --git a/dll/win32/imm32/utils.c b/dll/win32/imm32/utils.c
index b3618536782..d135932b25a 100644
--- a/dll/win32/imm32/utils.c
+++ b/dll/win32/imm32/utils.c
@@ -167,7 +167,7 @@ static PVOID FASTCALL DesktopPtrToUser(PVOID ptr)
return (PVOID)NtUserCallOneParam((DWORD_PTR)ptr,
ONEPARAM_ROUTINE_GETDESKTOPMAPPING);
}
-// Win: HMValidateHandle
+// Win: HMValidateHandleNoRip
LPVOID FASTCALL ValidateHandleNoErr(HANDLE hObject, UINT uType)
{
UINT index;
@@ -203,14 +203,18 @@ LPVOID FASTCALL ValidateHandleNoErr(HANDLE hObject, UINT uType)
return ptr;
}
-PWND FASTCALL ValidateHwndNoErr(HWND hwnd)
+// Win: HMValidateHandle
+LPVOID FASTCALL ValidateHandle(HANDLE hObject, UINT uType)
{
- /* See if the window is cached */
- PCLIENTINFO ClientInfo = GetWin32ClientInfo();
- if (hwnd == ClientInfo->CallbackWnd.hWnd)
- return ClientInfo->CallbackWnd.pWnd;
+ LPVOID pvObj = ValidateHandleNoErr(hObject, uType);
+ if (pvObj)
+ return pvObj;
- return ValidateHandleNoErr(hwnd, TYPE_WINDOW);
+ if (uType == TYPE_WINDOW)
+ SetLastError(ERROR_INVALID_WINDOW_HANDLE);
+ else
+ SetLastError(ERROR_INVALID_HANDLE);
+ return NULL;
}
// Win: TestInputContextProcess