diff options
| author | 2021-01-23 18:24:57 +1100 | |
|---|---|---|
| committer | 2021-01-23 18:24:57 +1100 | |
| commit | df4210032060ac271bb6c909d489ff094e16b7b9 (patch) | |
| tree | b8019bec3e4b4a7b86ffdb362635f5b2535a1984 /src | |
| parent | Mark DestinationToString as static (diff) | |
| download | yuzu-df4210032060ac271bb6c909d489ff094e16b7b9.tar.gz yuzu-df4210032060ac271bb6c909d489ff094e16b7b9.tar.xz yuzu-df4210032060ac271bb6c909d489ff094e16b7b9.zip | |
Clamp string reads to buffer size
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/lm/lm.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index 4e0b4ea09..90e9e691a 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/src/core/hle/service/lm/lm.cpp | |||
| @@ -162,9 +162,11 @@ private: | |||
| 162 | if (length == 0) { | 162 | if (length == 0) { |
| 163 | return std::nullopt; | 163 | return std::nullopt; |
| 164 | } | 164 | } |
| 165 | std::string output(length, '\0'); | 165 | const auto length_to_read = std::min(length, data.size() - offset); |
| 166 | std::memcpy(output.data(), data.data() + offset, length); | 166 | |
| 167 | offset += length; | 167 | std::string output(length_to_read, '\0'); |
| 168 | std::memcpy(output.data(), data.data() + offset, length_to_read); | ||
| 169 | offset += length_to_read; | ||
| 168 | return output; | 170 | return output; |
| 169 | } | 171 | } |
| 170 | 172 | ||