From eabc1f2b00f79a5dd3074acdba773bf675ef9833 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 3 Oct 2018 22:03:51 -0400 Subject: [PATCH 1/2] make WiFi.softAP() more robust --- libraries/WiFi/src/WiFiAP.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/libraries/WiFi/src/WiFiAP.cpp b/libraries/WiFi/src/WiFiAP.cpp index 8f96add91bc..91fc5178b70 100644 --- a/libraries/WiFi/src/WiFiAP.cpp +++ b/libraries/WiFi/src/WiFiAP.cpp @@ -97,32 +97,27 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, return false; } - if(!ssid || *ssid == 0 || strlen(ssid) > 31) { - // fail SSID too long or missing! - return false; - } - - if(passphrase && (strlen(passphrase) > 63 || strlen(passphrase) < 8)) { - // fail passphrase to long or short! + if(!ssid || *ssid == 0) { + // fail SSID missing! return false; } esp_wifi_start(); wifi_config_t conf; - strcpy(reinterpret_cast(conf.ap.ssid), ssid); + strlcpy(reinterpret_cast(conf.ap.ssid), ssid, sizeof(conf.ap.ssid)); conf.ap.channel = channel; - conf.ap.ssid_len = strlen(ssid); + conf.ap.ssid_len = strlen(reinterpret_cast(conf.ap.ssid)); conf.ap.ssid_hidden = ssid_hidden; conf.ap.max_connection = max_connection; conf.ap.beacon_interval = 100; - if(!passphrase || strlen(passphrase) == 0) { + if(!passphrase || strlen(passphrase) < 8) { conf.ap.authmode = WIFI_AUTH_OPEN; *conf.ap.password = 0; } else { conf.ap.authmode = WIFI_AUTH_WPA2_PSK; - strcpy(reinterpret_cast(conf.ap.password), passphrase); + strlcpy(reinterpret_cast(conf.ap.password), passphrase, sizeof(conf.ap.password)); } wifi_config_t conf_current; From 0c8337bfcf00360d8711cc3b7fc810479796504c Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 3 Oct 2018 23:54:10 -0400 Subject: [PATCH 2/2] WiFi.softAP() revert fallback to WIFI_AUTH_OPEN --- libraries/WiFi/src/WiFiAP.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libraries/WiFi/src/WiFiAP.cpp b/libraries/WiFi/src/WiFiAP.cpp index 91fc5178b70..8b7bbf15701 100644 --- a/libraries/WiFi/src/WiFiAP.cpp +++ b/libraries/WiFi/src/WiFiAP.cpp @@ -94,11 +94,19 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, if(!WiFi.enableAP(true)) { // enable AP failed + log_e("enable AP first!"); return false; } if(!ssid || *ssid == 0) { - // fail SSID missing! + // fail SSID missing + log_e("SSID missing!"); + return false; + } + + if(passphrase && (strlen(passphrase) > 0 && strlen(passphrase) < 8)) { + // fail passphrase too short + log_e("passphrase too short!"); return false; } @@ -112,7 +120,7 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, conf.ap.max_connection = max_connection; conf.ap.beacon_interval = 100; - if(!passphrase || strlen(passphrase) < 8) { + if(!passphrase || strlen(passphrase) == 0) { conf.ap.authmode = WIFI_AUTH_OPEN; *conf.ap.password = 0; } else {