소스 검색

Clamp string reads to buffer size

Chloe Marcec 5 년 전
부모
커밋
df42100320
1개의 변경된 파일5개의 추가작업 그리고 3개의 파일을 삭제
  1. 5 3
      src/core/hle/service/lm/lm.cpp

+ 5 - 3
src/core/hle/service/lm/lm.cpp

@@ -162,9 +162,11 @@ private:
         if (length == 0) {
             return std::nullopt;
         }
-        std::string output(length, '\0');
-        std::memcpy(output.data(), data.data() + offset, length);
-        offset += length;
+        const auto length_to_read = std::min(length, data.size() - offset);
+
+        std::string output(length_to_read, '\0');
+        std::memcpy(output.data(), data.data() + offset, length_to_read);
+        offset += length_to_read;
         return output;
     }