mirror of
https://github.com/yuzu-emu/yuzu-android
synced 2024-12-24 21:11:20 -08:00
Merge pull request #7172 from Morph1984/out-of-bounds
string_util: Prevent out of bounds access in u16string_view buffer
This commit is contained in:
commit
764369f4c7
@ -180,20 +180,20 @@ std::wstring UTF8ToUTF16W(const std::string& input) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len) {
|
std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer, std::size_t max_len) {
|
||||||
std::size_t len = 0;
|
std::size_t len = 0;
|
||||||
while (len < max_len && buffer[len] != '\0')
|
while (len < buffer.length() && len < max_len && buffer[len] != '\0') {
|
||||||
++len;
|
++len;
|
||||||
|
}
|
||||||
return std::string(buffer, len);
|
return std::string(buffer.begin(), buffer.begin() + len);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer,
|
std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer,
|
||||||
std::size_t max_len) {
|
std::size_t max_len) {
|
||||||
std::size_t len = 0;
|
std::size_t len = 0;
|
||||||
while (len < max_len && buffer[len] != '\0')
|
while (len < buffer.length() && len < max_len && buffer[len] != '\0') {
|
||||||
++len;
|
++len;
|
||||||
|
}
|
||||||
return std::u16string(buffer.begin(), buffer.begin() + len);
|
return std::u16string(buffer.begin(), buffer.begin() + len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ template <typename InIt>
|
|||||||
* Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't
|
* Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't
|
||||||
* NUL-terminated then the string ends at max_len characters.
|
* NUL-terminated then the string ends at max_len characters.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(const char* buffer,
|
[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer,
|
||||||
std::size_t max_len);
|
std::size_t max_len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user