From ecd958e50ef857e5422b18d153c8a8f2194bd421 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 18 Sep 2022 04:03:22 -0400 Subject: [PATCH] String: Fix remove method strncpy() can not use overlapped memory regions and generates corrupted data with certain inputs. Changed to memmove. Verified with fuzzing against std::string::erase. --- cores/arduino/WString.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index 775fce1..da1328a 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -735,7 +735,7 @@ void String::remove(unsigned int index, unsigned int count) } char *writeTo = buffer + index; len = len - count; - strncpy(writeTo, buffer + index + count, len - index); + memmove(writeTo, buffer + index + count, len - index); buffer[len] = 0; }