[NTUSER][USER32] NtUserGetKeyboardLayoutName and GetKeyboardLayoutNameW (#4595)
authorKatayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
Fri, 5 Aug 2022 23:02:31 +0000 (08:02 +0900)
committerGitHub <noreply@github.com>
Fri, 5 Aug 2022 23:02:31 +0000 (08:02 +0900)
#4594 has proved that the 1st argument of NtUserGetKeyboardLayoutName has type PUNICODE_STRING.
CORE-11700

modules/rostests/apitests/win32u/win32u_2k3sp2/win32u_2k3sp2.spec
modules/rostests/apitests/win32u/win32u_ros/win32u_ros.spec
modules/rostests/apitests/win32u/win32u_vista/win32u_vista.spec
modules/rostests/apitests/win32u/win32u_xpsp2/win32u_xpsp2.spec
win32ss/include/ntuser.h
win32ss/user/ntuser/kbdlayout.c
win32ss/user/user32/windows/input.c

index d09cec8..f3bd707 100644 (file)
 @ stdcall NtUserGetImeInfoEx(long long)
 @ stdcall NtUserGetInternalWindowPos(ptr ptr ptr)
 @ stdcall NtUserGetKeyboardLayoutList(long ptr)
-@ stdcall NtUserGetKeyboardLayoutName(str)
+@ stdcall NtUserGetKeyboardLayoutName(ptr)
 @ stdcall NtUserGetKeyboardState(ptr)
 @ stdcall NtUserGetKeyNameText(long wstr long)
 @ stdcall NtUserGetKeyState(long)
index 6fe82b2..d307cec 100644 (file)
 @ stdcall NtUserGetImeInfoEx(long long)
 @ stdcall NtUserGetInternalWindowPos(ptr ptr ptr)
 @ stdcall NtUserGetKeyboardLayoutList(long ptr)
-@ stdcall NtUserGetKeyboardLayoutName(str)
+@ stdcall NtUserGetKeyboardLayoutName(ptr)
 @ stdcall NtUserGetKeyboardState(ptr)
 @ stdcall NtUserGetKeyNameText(long wstr long)
 @ stdcall NtUserGetKeyState(long)
index 8b716bb..2c39932 100644 (file)
 @ stdcall NtUserGetImeInfoEx(long long)
 @ stdcall NtUserGetInternalWindowPos(ptr ptr ptr)
 @ stdcall NtUserGetKeyboardLayoutList(long ptr)
-@ stdcall NtUserGetKeyboardLayoutName(str)
+@ stdcall NtUserGetKeyboardLayoutName(ptr)
 @ stdcall NtUserGetKeyboardState(ptr)
 @ stdcall NtUserGetKeyNameText(long wstr long)
 @ stdcall NtUserGetKeyState(long)
index bd059a8..ecf140a 100644 (file)
 @ stdcall NtUserGetImeInfoEx(long long)
 @ stdcall NtUserGetInternalWindowPos(ptr ptr ptr)
 @ stdcall NtUserGetKeyboardLayoutList(long ptr)
-@ stdcall NtUserGetKeyboardLayoutName(str)
+@ stdcall NtUserGetKeyboardLayoutName(ptr)
 @ stdcall NtUserGetKeyboardState(ptr)
 @ stdcall NtUserGetKeyNameText(long wstr long)
 @ stdcall NtUserGetKeyState(long)
index 7dde3b3..531d833 100644 (file)
@@ -2431,7 +2431,7 @@ NtUserGetKeyboardLayoutList(
 BOOL
 NTAPI
 NtUserGetKeyboardLayoutName(
-    LPWSTR lpszName);
+    _Inout_ PUNICODE_STRING pustrName);
 
 DWORD
 NTAPI
index bca41fa..a91a641 100644 (file)
@@ -649,11 +649,12 @@ Quit:
 BOOL
 APIENTRY
 NtUserGetKeyboardLayoutName(
-    LPWSTR pwszName)
+    _Inout_ PUNICODE_STRING pustrName)
 {
     BOOL bRet = FALSE;
     PKL pKl;
     PTHREADINFO pti;
+    UNICODE_STRING ustrTemp;
 
     UserEnterShared();
 
@@ -665,8 +666,24 @@ NtUserGetKeyboardLayoutName(
 
     _SEH2_TRY
     {
-        ProbeForWrite(pwszName, KL_NAMELENGTH*sizeof(WCHAR), 1);
-        wcscpy(pwszName, pKl->spkf->awchKF);
+        ProbeForWriteUnicodeString(pustrName);
+        ProbeForWrite(pustrName->Buffer, pustrName->MaximumLength, 1);
+
+        if (IS_IME_HKL(pKl->hkl))
+        {
+            RtlIntegerToUnicodeString((ULONG)(ULONG_PTR)pKl->hkl, 16, pustrName);
+        }
+        else
+        {
+            if (pustrName->MaximumLength < KL_NAMELENGTH * sizeof(WCHAR))
+            {
+                EngSetLastError(ERROR_INVALID_PARAMETER);
+                goto cleanup;
+            }
+            RtlInitUnicodeString(&ustrTemp, pKl->spkf->awchKF); /* FIXME: Do not use awchKF */
+            RtlCopyUnicodeString(pustrName, &ustrTemp);
+        }
+
         bRet = TRUE;
     }
     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
index 50189f8..1de1dc0 100644 (file)
@@ -584,7 +584,13 @@ GetKeyboardLayoutNameA(LPSTR pwszKLID)
 BOOL WINAPI
 GetKeyboardLayoutNameW(LPWSTR pwszKLID)
 {
-    return NtUserGetKeyboardLayoutName(pwszKLID);
+    UNICODE_STRING Name;
+
+    RtlInitEmptyUnicodeString(&Name,
+                              pwszKLID,
+                              KL_NAMELENGTH * sizeof(WCHAR));
+
+    return NtUserGetKeyboardLayoutName(&Name);
 }
 
 /*