1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

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

This commit is contained in:
Paulo Cabral Sanz 2022-06-12 18:22:15 -03:00 committed by GitHub
parent 9ace4ed849
commit bdc71e5801
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -260,7 +260,8 @@ String &String::copy(const char *cstr, unsigned int length) {
return *this; return *this;
} }
setLen(length); setLen(length);
memmove_P(wbuffer(), cstr, length + 1); memmove_P(wbuffer(), cstr, length);
wbuffer()[length] = 0;
return *this; return *this;
} }
@ -270,7 +271,8 @@ String &String::copy(const __FlashStringHelper *pstr, unsigned int length) {
return *this; return *this;
} }
setLen(length); 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; return *this;
} }
@ -411,8 +413,9 @@ bool String::concat(const __FlashStringHelper *str) {
unsigned int newlen = len() + length; unsigned int newlen = len() + length;
if (!reserve(newlen)) if (!reserve(newlen))
return false; return false;
memcpy_P(wbuffer() + len(), (PGM_P)str, length + 1); memcpy_P(wbuffer() + len(), (PGM_P)str, length);
setLen(newlen); setLen(newlen);
wbuffer()[newlen] = 0;
return true; return true;
} }