From 956896c50bbac8721c63ae1855f062afb64e4108 Mon Sep 17 00:00:00 2001 From: bilaliscarioth <98892516+bilaliscarioth@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:58:34 +0100 Subject: [PATCH 1/2] Replace strpcy by strlcpy Many edge case can be caused by strcpy, cause length not is taked care. --- 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 043fda7c0..1922f2e9b 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -266,7 +266,7 @@ unsigned char String::concat(const char *cstr, unsigned int length) if (!cstr) return 0; if (length == 0) return 1; if (!reserve(newlen)) return 0; - strcpy(buffer + len, cstr); + strlcpy(buffer + len, cstr, length); len = newlen; return 1; } From a4fdb6c8a706f8958bff4fa0de6398f45e1ca9b5 Mon Sep 17 00:00:00 2001 From: bilaliscarioth <98892516+bilaliscarioth@users.noreply.github.com> Date: Thu, 16 Jan 2025 22:37:26 +0100 Subject: [PATCH 2/2] test with memcpy Checking if memcpy use less than strlcpy --- 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 1922f2e9b..f6dd2b2ff 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -266,7 +266,7 @@ unsigned char String::concat(const char *cstr, unsigned int length) if (!cstr) return 0; if (length == 0) return 1; if (!reserve(newlen)) return 0; - strlcpy(buffer + len, cstr, length); + memcpy(buffer + len, cstr, length); len = newlen; return 1; }