https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b7dcc1024b001e45f3cec…
commit b7dcc1024b001e45f3cecf945ff46ff1e79f4c5a
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sat Dec 9 09:49:57 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Dec 9 09:49:57 2023 +0900
[IMM32] Rewrite ImmLoadLayout (#6138)
ImmLoadLayout was buggy.
- Don't do zero fill pImeInfoEx.
- Simplify registry handling.
- Don't reset pImeInfoEx->fLoadFlag if failed early.
CORE-19268
---
dll/win32/imm32/imm.c | 46 +++++++++++++++++++++-------------------------
dll/win32/imm32/precomp.h | 1 -
2 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/dll/win32/imm32/imm.c b/dll/win32/imm32/imm.c
index aa81c0935bd..d3d4b7dcb07 100644
--- a/dll/win32/imm32/imm.c
+++ b/dll/win32/imm32/imm.c
@@ -67,49 +67,45 @@ BOOL WINAPI ImmRegisterClient(PSHAREDINFO ptr, HINSTANCE hMod)
BOOL WINAPI ImmLoadLayout(HKL hKL, PIMEINFOEX pImeInfoEx)
{
DWORD cbData, dwType;
- HKEY hLayoutKey;
- LONG error;
+ HKEY hKey;
+ LSTATUS error;
WCHAR szLayout[MAX_PATH];
+ LPCWSTR pszSubKey;
TRACE("(%p, %p)\n", hKL, pImeInfoEx);
- ZeroMemory(pImeInfoEx, sizeof(IMEINFOEX));
-
- if (IS_IME_HKL(hKL) || !IS_CICERO_MODE() || IS_16BIT_MODE())
+ /* Choose a key */
+ if (IS_IME_HKL(hKL) || !IS_CICERO_MODE() || IS_16BIT_MODE()) /* Non-Cicero? */
{
StringCchPrintfW(szLayout, _countof(szLayout), L"%s\\%08lX",
REGKEY_KEYBOARD_LAYOUTS, HandleToUlong(hKL));
-
- error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szLayout, 0, KEY_READ,
&hLayoutKey);
- if (IS_ERROR_UNEXPECTEDLY(error))
- return FALSE;
+ pszSubKey = szLayout;
}
- else
+ else /* Cicero */
{
- error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, REGKEY_IMM, 0, KEY_READ,
&hLayoutKey);
- if (IS_ERROR_UNEXPECTEDLY(error))
- return FALSE;
+ pszSubKey = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\IMM";
}
+ /* Open the key */
+ error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, pszSubKey, 0, KEY_READ, &hKey);
+ if (IS_ERROR_UNEXPECTEDLY(error))
+ return FALSE;
+
+ /* Load "IME File" value */
cbData = sizeof(pImeInfoEx->wszImeFile);
- error = RegQueryValueExW(hLayoutKey, L"Ime File", NULL, &dwType,
+ error = RegQueryValueExW(hKey, L"IME File", NULL, &dwType,
(LPBYTE)pImeInfoEx->wszImeFile, &cbData);
- pImeInfoEx->wszImeFile[_countof(pImeInfoEx->wszImeFile) - 1] = UNICODE_NULL;
-
- RegCloseKey(hLayoutKey);
- pImeInfoEx->fLoadFlag = 0;
+ /* Avoid buffer overrun */
+ pImeInfoEx->wszImeFile[_countof(pImeInfoEx->wszImeFile) - 1] = UNICODE_NULL;
- if (IS_ERROR_UNEXPECTEDLY(error))
- return FALSE;
+ RegCloseKey(hKey);
- if (dwType != REG_SZ)
- {
- ERR("\n");
- return FALSE;
- }
+ if (error != ERROR_SUCCESS || dwType != REG_SZ)
+ return FALSE; /* Failed */
pImeInfoEx->hkl = hKL;
+ pImeInfoEx->fLoadFlag = 0;
return Imm32LoadImeVerInfo(pImeInfoEx);
}
diff --git a/dll/win32/imm32/precomp.h b/dll/win32/imm32/precomp.h
index cb87f48890c..7bb2569777b 100644
--- a/dll/win32/imm32/precomp.h
+++ b/dll/win32/imm32/precomp.h
@@ -58,7 +58,6 @@
#define LANGID_JAPANESE MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT)
#define REGKEY_KEYBOARD_LAYOUTS L"System\\CurrentControlSet\\Control\\Keyboard
Layouts"
-#define REGKEY_IMM L"Software\\Microsoft\\Windows
NT\\CurrentVersion\\IMM"
#define ROUNDUP4(n) (((n) + 3) & ~3) /* DWORD alignment */