Skip to content

Commit 6f42d7b

Browse files
igrrd-a-v
authored andcommitted
pgmspace: zero out memory in strncpy_P (esp8266#2633)
strncpy should write 'size' characters, padding with zeroes if src is shorter than 'size'.
1 parent 019de9c commit 6f42d7b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cores/esp8266/pgmspace.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ void* memmem_P(const void* buf, size_t bufSize, PGM_VOID_P findP, size_t findPSi
147147

148148

149149
char* strncpy_P(char* dest, PGM_P src, size_t size) {
150+
bool size_known = (size != SIZE_IRRELEVANT);
150151
const char* read = src;
151152
char* write = dest;
152153
char ch = '.';
@@ -156,6 +157,14 @@ char* strncpy_P(char* dest, PGM_P src, size_t size) {
156157
*write++ = ch;
157158
size--;
158159
}
160+
if (size_known)
161+
{
162+
while (size > 0)
163+
{
164+
*write++ = 0;
165+
size--;
166+
}
167+
}
159168

160169
return dest;
161170
}

0 commit comments

Comments
 (0)