From de9e8e024b2fd811f10a75ee8933a6d10f5f3cc9 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 13 Oct 2017 02:17:06 +0800 Subject: [PATCH] pgmspace: zero out memory in strncpy_P (#2633) strncpy should write 'size' characters, padding with zeroes if src is shorter than 'size'. --- cores/esp8266/pgmspace.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cores/esp8266/pgmspace.cpp b/cores/esp8266/pgmspace.cpp index ed81039f46..e705a32f64 100644 --- a/cores/esp8266/pgmspace.cpp +++ b/cores/esp8266/pgmspace.cpp @@ -147,6 +147,7 @@ void* memmem_P(const void* buf, size_t bufSize, PGM_VOID_P findP, size_t findPSi char* strncpy_P(char* dest, PGM_P src, size_t size) { + bool size_known = (size != SIZE_IRRELEVANT); const char* read = src; char* write = dest; char ch = '.'; @@ -156,6 +157,14 @@ char* strncpy_P(char* dest, PGM_P src, size_t size) { *write++ = ch; size--; } + if (size_known) + { + while (size > 0) + { + *write++ = 0; + size--; + } + } return dest; }