Skip to content

Commit 3470796

Browse files
authored
Fix potential out of range in String::concat
There is no prerequisite the given array has to be a 0-terminated char array. So we should only copy the length that has been given. The `setLen()` function will make sure the internal string is 0-terminated. So no need to dangerously assume there will be 1 more byte to copy
1 parent 6fcaf69 commit 3470796

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: cores/esp32/WString.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ bool String::concat(const char *cstr, unsigned int length) {
343343
}
344344
if (cstr >= wbuffer() && cstr < wbuffer() + len()) {
345345
// compatible with SSO in ram #6155 (case "x += x.c_str()")
346-
memmove(wbuffer() + len(), cstr, length + 1);
346+
memmove(wbuffer() + len(), cstr, length);
347347
} else {
348348
// compatible with source in flash #6367
349-
memcpy_P(wbuffer() + len(), cstr, length + 1);
349+
memcpy_P(wbuffer() + len(), cstr, length);
350350
}
351351
setLen(newlen);
352352
return true;

0 commit comments

Comments
 (0)