From 18098cbb46c2d3bd28f6a7b1aeb739f0d9a0a24a Mon Sep 17 00:00:00 2001 From: acevest Date: Mon, 17 Dec 2018 23:11:47 +0800 Subject: [PATCH 1/2] in sta mode, empty passphrase should not use secure auth mode --- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index b9a0fdf121..7ae555afd6 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -113,21 +113,22 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase, return WL_CONNECT_FAILED; } - if(passphrase && strlen(passphrase) > 64) { + int passphrase_len = passphrase == NULL ? 0 : strlen(passphrase); + if(passphrase_len > 64) { // fail passphrase too long! return WL_CONNECT_FAILED; } struct station_config conf; + conf.threshold.authmode = passphrase_len == 0 ? AUTH_OPEN : _useInsecureWEP ? AUTH_WEP : AUTH_WPA_PSK; + if(strlen(ssid) == 32) memcpy(reinterpret_cast(conf.ssid), ssid, 32); //copied in without null term else strcpy(reinterpret_cast(conf.ssid), ssid); - conf.threshold.authmode = AUTH_OPEN; if(passphrase) { - conf.threshold.authmode = _useInsecureWEP ? AUTH_WEP : AUTH_WPA_PSK; - if (strlen(passphrase) == 64) // it's not a passphrase, is the PSK, which is copied into conf.password without null term + if (passphrase_len == 64) // it's not a passphrase, is the PSK, which is copied into conf.password without null term memcpy(reinterpret_cast(conf.password), passphrase, 64); else strcpy(reinterpret_cast(conf.password), passphrase); From b37fe5ad9ba5f78978b8fb4d1b3e10666b561c7a Mon Sep 17 00:00:00 2001 From: AceVest Date: Tue, 18 Dec 2018 00:39:36 +0800 Subject: [PATCH 2/2] use nullptr, camelCase and parenthesis --- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index 7ae555afd6..3e6967b705 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -113,14 +113,14 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase, return WL_CONNECT_FAILED; } - int passphrase_len = passphrase == NULL ? 0 : strlen(passphrase); - if(passphrase_len > 64) { + int passphraseLen = passphrase == nullptr ? 0 : strlen(passphrase); + if(passphraseLen > 64) { // fail passphrase too long! return WL_CONNECT_FAILED; } struct station_config conf; - conf.threshold.authmode = passphrase_len == 0 ? AUTH_OPEN : _useInsecureWEP ? AUTH_WEP : AUTH_WPA_PSK; + conf.threshold.authmode = (passphraseLen == 0) ? AUTH_OPEN : (_useInsecureWEP ? AUTH_WEP : AUTH_WPA_PSK); if(strlen(ssid) == 32) memcpy(reinterpret_cast(conf.ssid), ssid, 32); //copied in without null term @@ -128,7 +128,7 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase, strcpy(reinterpret_cast(conf.ssid), ssid); if(passphrase) { - if (passphrase_len == 64) // it's not a passphrase, is the PSK, which is copied into conf.password without null term + if (passphraseLen == 64) // it's not a passphrase, is the PSK, which is copied into conf.password without null term memcpy(reinterpret_cast(conf.password), passphrase, 64); else strcpy(reinterpret_cast(conf.password), passphrase);