Skip to content

Commit 2946ce0

Browse files
authored
Avoid copying past end of buffer in String.concat (#8198)
1 parent a105bdd commit 2946ce0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Diff for: cores/esp8266/WString.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ bool String::concat(const char *cstr, unsigned int length) {
305305
return true;
306306
if (!reserve(newlen))
307307
return false;
308-
memmove_P(wbuffer() + len(), cstr, length + 1);
308+
memmove_P(wbuffer() + len(), cstr, length);
309309
setLen(newlen);
310310
wbuffer()[newlen] = 0;
311311
return true;

Diff for: tests/host/core/test_string.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -594,3 +594,13 @@ TEST_CASE("String chaining", "[core][String]")
594594
REQUIRE(static_cast<const void*>(result.c_str()) == static_cast<const void*>(ptr));
595595
}
596596
}
597+
598+
TEST_CASE("String concat OOB #8198", "[core][String]")
599+
{
600+
char *p = (char*)malloc(16);
601+
memset(p, 'x', 16);
602+
String s = "abcd";
603+
s.concat(p, 16);
604+
REQUIRE(!strcmp(s.c_str(), "abcdxxxxxxxxxxxxxxxx"));
605+
free(p);
606+
}

0 commit comments

Comments
 (0)