From 933f86720ab8a12d7a74ad67ad6710e189861fa0 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 13 Jul 2018 23:43:07 -0500 Subject: [PATCH] param was using user length for strncpy, causing overflows --- WiFiManager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 576d10f..0e4f36f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -63,12 +63,17 @@ WiFiManagerParameter::~WiFiManagerParameter() { void WiFiManagerParameter::setValue(const char *defaultValue, int length) { _length = length; + length = strlen(defaultValue); // length actual + if(_length < length){ + // Serial.println("defaultValue length mismatch"); + } _value = new char[length + 1]; for (int i = 0; i < length + 1; i++) { _value[i] = 0; } if (defaultValue != NULL) { - strncpy(_value, defaultValue, length + 1); // length+1 due to null terminated string + strncpy(_value, defaultValue, length); + _value[length] = '\0'; // explicit null } } const char* WiFiManagerParameter::getValue() {