Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid reading past end of non-zero terminated char arrays #8597

Merged
merged 2 commits into from
Jun 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cores/esp8266/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ String &String::copy(const char *cstr, unsigned int length) {
return *this;
}
setLen(length);
memmove_P(wbuffer(), cstr, length + 1);
memmove_P(wbuffer(), cstr, length);
wbuffer()[length] = 0;
return *this;
}

Expand All @@ -270,7 +271,8 @@ String &String::copy(const __FlashStringHelper *pstr, unsigned int length) {
return *this;
}
setLen(length);
memcpy_P(wbuffer(), (PGM_P)pstr, length + 1); // We know wbuffer() cannot ever be in PROGMEM, so memcpy safe here
memcpy_P(wbuffer(), (PGM_P)pstr, length); // We know wbuffer() cannot ever be in PROGMEM, so memcpy safe here
wbuffer()[length] = 0;
return *this;
}

Expand Down Expand Up @@ -411,8 +413,9 @@ bool String::concat(const __FlashStringHelper *str) {
unsigned int newlen = len() + length;
if (!reserve(newlen))
return false;
memcpy_P(wbuffer() + len(), (PGM_P)str, length + 1);
memcpy_P(wbuffer() + len(), (PGM_P)str, length);
d-a-v marked this conversation as resolved.
Show resolved Hide resolved
setLen(newlen);
wbuffer()[newlen] = 0;
return true;
}

Expand Down