瀏覽代碼

applets/swkbd: Only read the text check message on Failure/Confirm

Applications may leave this region of memory uninitialized when the text check result is not either Failure or Confirm.
Attempting to read uninitialized memory may cause an exception within the UTF16 to UTF8 string converter.
Fix this by only reading the text check message on Failure or Confirm.
Morph 5 年之前
父節點
當前提交
247cd92216
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      src/core/hle/service/am/applets/software_keyboard.cpp

+ 7 - 2
src/core/hle/service/am/applets/software_keyboard.cpp

@@ -273,8 +273,13 @@ void SoftwareKeyboard::ProcessTextCheck() {
 
 
     std::memcpy(&swkbd_text_check, text_check_data.data(), sizeof(SwkbdTextCheck));
     std::memcpy(&swkbd_text_check, text_check_data.data(), sizeof(SwkbdTextCheck));
 
 
-    std::u16string text_check_message = Common::UTF16StringFromFixedZeroTerminatedBuffer(
-        swkbd_text_check.text_check_message.data(), swkbd_text_check.text_check_message.size());
+    std::u16string text_check_message =
+        swkbd_text_check.text_check_result == SwkbdTextCheckResult::Failure ||
+                swkbd_text_check.text_check_result == SwkbdTextCheckResult::Confirm
+            ? Common::UTF16StringFromFixedZeroTerminatedBuffer(
+                  swkbd_text_check.text_check_message.data(),
+                  swkbd_text_check.text_check_message.size())
+            : u"";
 
 
     LOG_INFO(Service_AM, "\nTextCheckResult: {}\nTextCheckMessage: {}",
     LOG_INFO(Service_AM, "\nTextCheckResult: {}\nTextCheckMessage: {}",
              GetTextCheckResultName(swkbd_text_check.text_check_result),
              GetTextCheckResultName(swkbd_text_check.text_check_result),