From df4210032060ac271bb6c909d489ff094e16b7b9 Mon Sep 17 00:00:00 2001 From: Chloe Marcec Date: Sat, 23 Jan 2021 18:24:57 +1100 Subject: [PATCH] Clamp string reads to buffer size --- src/core/hle/service/lm/lm.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index 4e0b4ea090..90e9e691a4 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/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; }