From 5a06f29c5b96b973aa5a8e2ecaa5192d01abab3d Mon Sep 17 00:00:00 2001 From: Christopher Liebman Date: Sat, 7 Jul 2018 06:26:36 -0700 Subject: [PATCH 01/12] In https://github.com/esp8266/Arduino/pull/4889 the core was modified to disable WPS by default. Its only enabled if NO_EXTRA_4K_HEAP is defined. To enable you must re-run the board manager with --noextra4kheap. This addes #ifdef NO_EXTRA_4K_HEAP arround WPS usage so it won't generate compiler errors. --- WiFiManager.cpp | 5 ++++- WiFiManager.h | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index fdeae7c..9a09195 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -654,6 +654,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { DEBUG_WM(DEBUG_VERBOSE,F("Connection result:"),getWLStatusString(connRes)); +#ifdef NO_EXTRA_4K_HEAP // do WPS, if WPS options enabled and not connected and no password was supplied // @todo this seems like wrong place for this, is it a fallback or option? if (_tryWPS && connRes != WL_CONNECTED && pass == "") { @@ -661,6 +662,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { // should be connected at the end of WPS connRes = waitForConnectResult(); } +#endif if(connRes != WL_SCAN_COMPLETED){ updateConxResult(connRes); @@ -782,6 +784,7 @@ uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) { return status; } +#ifdef NO_EXTRA_4K_HEAP void WiFiManager::startWPS() { DEBUG_WM(F("START WPS")); #ifdef ESP8266 @@ -791,7 +794,7 @@ void WiFiManager::startWPS() { #endif DEBUG_WM(F("END WPS")); } - +#endif String WiFiManager::getHTTPHead(String title){ String page; diff --git a/WiFiManager.h b/WiFiManager.h index 6779dcb..795f67d 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -290,7 +290,9 @@ class WiFiManager int _staShowDns = 0; // ternary always show dns, only if not set in code, never(cannot change dns via web!) boolean _removeDuplicateAPs = true; // remove dup aps from wifiscan boolean _shouldBreakAfterConfig = false; // stop configportal on save failure +#ifdef NO_EXTRA_4K_HEAP boolean _tryWPS = false; // try WPS on save failure, unsupported +#endif boolean _configPortalIsBlocking = true; // configportal enters blocking loop boolean _enableCaptivePortal = true; // enable captive portal redirection boolean _userpersistent = true; // users preffered persistence to restore @@ -316,7 +318,9 @@ class WiFiManager void _end(); void setupConfigPortal(); +#ifdef NO_EXTRA_4K_HEAP void startWPS(); +#endif bool startAP(); uint8_t connectWifi(String ssid, String pass); From b9f6b472a7cfde507dcc8ee19bbf8549aded220b Mon Sep 17 00:00:00 2001 From: tablatronix Date: Sat, 7 Jul 2018 09:45:24 -0500 Subject: [PATCH 02/12] #645 comments --- WiFiManager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 9a09195..c36c2c4 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -654,6 +654,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { DEBUG_WM(DEBUG_VERBOSE,F("Connection result:"),getWLStatusString(connRes)); +// WPS enabled? https://github.com/esp8266/Arduino/pull/4889 #ifdef NO_EXTRA_4K_HEAP // do WPS, if WPS options enabled and not connected and no password was supplied // @todo this seems like wrong place for this, is it a fallback or option? @@ -784,6 +785,7 @@ uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) { return status; } +// WPS enabled? https://github.com/esp8266/Arduino/pull/4889 #ifdef NO_EXTRA_4K_HEAP void WiFiManager::startWPS() { DEBUG_WM(F("START WPS")); From aeba5478ee7ddbdcfae3b4323f50600ca6e47e15 Mon Sep 17 00:00:00 2001 From: Christopher Liebman Date: Sun, 8 Jul 2018 07:14:11 -0700 Subject: [PATCH 03/12] fix bad progmem access introduced in https://github.com/tzapu/WiFiManager/pull/608 --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c36c2c4..6120d33 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1186,7 +1186,7 @@ void WiFiManager::handleWifiSave() { page += FPSTR(HTTP_END); server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); - server->sendHeader(HTTP_HEAD_CORS, HTTP_HEAD_CORS_ALLOW_ALL); + server->sendHeader(FPSTR(HTTP_HEAD_CORS), HTTP_HEAD_CORS_ALLOW_ALL); server->send(200, FPSTR(HTTP_HEAD_CT), page); DEBUG_WM(DEBUG_DEV,F("Sent wifi save page")); From e235a45d5a624e3eb380add327340071a2d3557d Mon Sep 17 00:00:00 2001 From: Chris Liebman Date: Sun, 8 Jul 2018 08:32:41 -0700 Subject: [PATCH 04/12] value is PROGMEM too.... --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 6120d33..0ee56e5 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1186,7 +1186,7 @@ void WiFiManager::handleWifiSave() { page += FPSTR(HTTP_END); server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); - server->sendHeader(FPSTR(HTTP_HEAD_CORS), HTTP_HEAD_CORS_ALLOW_ALL); + server->sendHeader(FPSTR(HTTP_HEAD_CORS), FPSTR(HTTP_HEAD_CORS_ALLOW_ALL)); server->send(200, FPSTR(HTTP_HEAD_CT), page); DEBUG_WM(DEBUG_DEV,F("Sent wifi save page")); From 24d317b9da270dbb4124e72da74aef0de7174632 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 13 Jul 2018 18:27:50 -0500 Subject: [PATCH 05/12] fix #655 --- WiFiManager.cpp | 2 +- strings_en.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c36c2c4..0245a88 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -800,7 +800,7 @@ void WiFiManager::startWPS() { String WiFiManager::getHTTPHead(String title){ String page; - page += FPSTR(HTTP_HEAD); + page += FPSTR(HTTP_HEAD_START); page.replace(FPSTR(T_v), title); page += FPSTR(HTTP_SCRIPT); page += FPSTR(HTTP_STYLE); diff --git a/strings_en.h b/strings_en.h index 5444d00..60850a2 100644 --- a/strings_en.h +++ b/strings_en.h @@ -17,7 +17,7 @@ // #define WIFI_MANAGER_OVERRIDE_STRINGS // Copy and paste ALL of the const char lines below and modify to suit. -const char HTTP_HEAD[] PROGMEM = "{v}"; +const char HTTP_HEAD_START[] PROGMEM = "{v}"; const char HTTP_SCRIPT[] PROGMEM = ""; const char HTTP_HEAD_END[] PROGMEM = "
"; From 17f2316ea84c694240b8ac7d02b20efce4e70ba4 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 13 Jul 2018 18:41:14 -0500 Subject: [PATCH 06/12] fixes #655 --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 0245a88..765b65b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1078,7 +1078,7 @@ String WiFiManager::getParamOut(){ String HTTP_PARAM_temp = FPSTR(HTTP_FORM_LABEL); HTTP_PARAM_temp += FPSTR(HTTP_FORM_PARAM); - bool tok_I = HTTP_PARAM_temp.indexOf(FPSTR(T_i)) > 0; + bool tok_I = HTTP_PARAM_temp.indexOf(FPSTR(T_I)) > 0; bool tok_i = HTTP_PARAM_temp.indexOf(FPSTR(T_i)) > 0; bool tok_n = HTTP_PARAM_temp.indexOf(FPSTR(T_n)) > 0; bool tok_p = HTTP_PARAM_temp.indexOf(FPSTR(T_p)) > 0; @@ -1113,7 +1113,7 @@ String WiFiManager::getParamOut(){ // if no ID use customhtml for item, else generate from param string if (_params[i]->getID() != NULL) { - if(tok_I)pitem.replace(FPSTR(T_i), (String)FPSTR(S_parampre)+(String)i); + if(tok_I)pitem.replace(FPSTR(T_I), (String)FPSTR(S_parampre)+(String)i); if(tok_i)pitem.replace(FPSTR(T_i), _params[i]->getID()); if(tok_n)pitem.replace(FPSTR(T_n), _params[i]->getID()); if(tok_p)pitem.replace(FPSTR(T_p), FPSTR(T_t)); From 933f86720ab8a12d7a74ad67ad6710e189861fa0 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 13 Jul 2018 23:43:07 -0500 Subject: [PATCH 07/12] 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() { From fc84e7a2607b0d35c750ce1b7983238d2e4bf87e Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 13 Jul 2018 23:52:36 -0500 Subject: [PATCH 08/12] trying to fix param issues when param is out of scope Ideally this should be done entirely different so params can follow wm scope and object lifetime.. --- WiFiManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 0e4f36f..45aa4bf 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -59,6 +59,7 @@ WiFiManagerParameter::~WiFiManagerParameter() { if (_value != NULL) { delete[] _value; } + _length=0; // setting length 0, ideally the entire parameter should be removed, or added to wifimanager scope so it follows } void WiFiManagerParameter::setValue(const char *defaultValue, int length) { @@ -1095,7 +1096,8 @@ String WiFiManager::getParamOut(){ char parLength[5]; // add the extra parameters to the form for (int i = 0; i < _paramsCount; i++) { - if (_params[i] == NULL) { + if (_params[i] == NULL || _params[i]->_length == 0) { + DEBUG_WM(DEBUG_ERROR,"[ERROR] WiFiManagerParameter is out of scope"); break; } From 85dd747949f302c022330dbd509107237fed7ecd Mon Sep 17 00:00:00 2001 From: Christopher Liebman Date: Sun, 15 Jul 2018 10:44:06 -0700 Subject: [PATCH 09/12] Use hasParam() instead of checking server.arg() for NULL, it returns a String anyway. Don't use .c_str() when its being assigned to a String anyway --- WiFiManager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 45aa4bf..fb5eb08 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1228,9 +1228,13 @@ void WiFiManager::doParamSave(){ break; } //read parameter from server + String name = (String)FPSTR(S_parampre)+(String)i; String value; - if(server->arg((String)FPSTR(S_parampre)+(String)i) != NULL) value = server->arg((String)FPSTR(S_parampre)+(String)i).c_str(); - else value = server->arg(_params[i]->getID()).c_str(); + if(server->hasArg(name)) { + value = server->arg(name); + } else { + value = server->arg(_params[i]->getID()); + } //store it in params array value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated From 2fac07cbf0228d49a479fa2811bf97591a2d532d Mon Sep 17 00:00:00 2001 From: Christopher Liebman Date: Sun, 15 Jul 2018 14:39:11 -0700 Subject: [PATCH 10/12] WiFiManagerParameter::setValue used length of default value for i allocation and not passed length. Changed to use passed length or length of default value if > passed length. --- WiFiManager.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index fb5eb08..477dde4 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -67,14 +67,16 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) { length = strlen(defaultValue); // length actual if(_length < length){ // Serial.println("defaultValue length mismatch"); + // use the length if it's longer. + _length = length; } - _value = new char[length + 1]; - for (int i = 0; i < length + 1; i++) { + _value = new char[_length + 1]; + for (int i = 0; i < _length + 1; i++) { _value[i] = 0; } if (defaultValue != NULL) { - strncpy(_value, defaultValue, length); - _value[length] = '\0'; // explicit null + strncpy(_value, defaultValue, _length); + _value[_length] = '\0'; // explicit null } } const char* WiFiManagerParameter::getValue() { @@ -1231,9 +1233,9 @@ void WiFiManager::doParamSave(){ String name = (String)FPSTR(S_parampre)+(String)i; String value; if(server->hasArg(name)) { - value = server->arg(name); + value = server->arg(name); } else { - value = server->arg(_params[i]->getID()); + value = server->arg(_params[i]->getID()); } //store it in params array From 9ab4deaf5bf0ff8163875a22f024a018f62f19e8 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 16 Jul 2018 08:06:03 -0500 Subject: [PATCH 11/12] clean up param length Just changing to not modify argument, spacing --- WiFiManager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 477dde4..a6a6091 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -63,14 +63,15 @@ WiFiManagerParameter::~WiFiManagerParameter() { } void WiFiManagerParameter::setValue(const char *defaultValue, int length) { - _length = length; - length = strlen(defaultValue); // length actual + _length = length; + deflength = strlen(defaultValue); // length actual + // use the defult length if it's longer, + // @todo consider it might be useful to fail, so user knows they were wrong if(_length < length){ // Serial.println("defaultValue length mismatch"); - // use the length if it's longer. - _length = length; + _length = deflength; } - _value = new char[_length + 1]; + _value = new char[_length + 1]; for (int i = 0; i < _length + 1; i++) { _value[i] = 0; } From 08bb2322aa2987702786752f9d450b4b622e8768 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 16 Jul 2018 17:07:31 -0500 Subject: [PATCH 12/12] Oops --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a6a6091..c21374f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -64,7 +64,7 @@ WiFiManagerParameter::~WiFiManagerParameter() { void WiFiManagerParameter::setValue(const char *defaultValue, int length) { _length = length; - deflength = strlen(defaultValue); // length actual + int deflength = strlen(defaultValue); // length actual // use the defult length if it's longer, // @todo consider it might be useful to fail, so user knows they were wrong if(_length < length){