Skip to content

Commit 00a52eb

Browse files
committed
[Valgrind] Fix buffer overrun in MCU_sttrtor8()
The char buffer passed to `MCU_strtor8()` is not guaranteed to be nul-terminated, which means that `strnlen` rather than `strlen` must be used if you want measure the length of the string in the buffer. Fixing this exposed a bug whereby the length `l` and string pointer `sptr` locals were not being reset after failing to parse an integer from the buffer.
1 parent 38b5704 commit 00a52eb

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

libfoundation/src/foundation-typeconvert.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ static real64_t MCU_strtor8(const char *&r_str, uindex_t &r_len, int8_t p_delim,
164164
r_done = done;
165165
return i;
166166
}
167-
l = MCMin(R8L - 1U, strlen(sptr));
167+
sptr = r_str;
168+
l = MCMin(R8L - 1U, strnlen(sptr, r_len));
168169
MCU_skip_spaces(sptr, l);
169170
// bugs in MSL means we need to check these things
170171
// MW-2006-04-21: [[ Purify ]] This was incorrect - we need to ensure l > 1 before running most

0 commit comments

Comments
 (0)