Skip to content

Commit b620060

Browse files
committed
do check if ssid is an empty String ""
use strdup to save some flash #386 part 2
1 parent c0df9b0 commit b620060

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFi.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t ch
6868
mode(WIFI_STA);
6969
}
7070

71-
if(!ssid || strlen(ssid) > 31) {
71+
if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
7272
// fail SSID to long or missing!
7373
return WL_CONNECT_FAILED;
7474
}
@@ -154,7 +154,7 @@ void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int chan
154154
mode(WIFI_AP);
155155
}
156156

157-
if(!ssid || strlen(ssid) > 31) {
157+
if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
158158
// fail SSID to long or missing!
159159
return;
160160
}

libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "ESP8266WiFiMulti.h"
2727
#include <limits.h>
28+
#include <string.h>
2829

2930
ESP8266WiFiMulti::ESP8266WiFiMulti() {
3031
}
@@ -151,7 +152,7 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
151152

152153
WifiAPlist_t newAP;
153154

154-
if(!ssid || strlen(ssid) > 31) {
155+
if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
155156
// fail SSID to long or missing!
156157
return false;
157158
}
@@ -161,21 +162,18 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
161162
return false;
162163
}
163164

164-
newAP.ssid = (char*) malloc((strlen(ssid) + 1));
165+
newAP.ssid = strdup(ssid);
165166

166167
if(!newAP.ssid) {
167168
return false;
168169
}
169170

170-
strcpy(newAP.ssid, ssid);
171-
172171
if(passphrase && *passphrase != 0x00) {
173-
newAP.passphrase = (char*) malloc((strlen(passphrase) + 1));
172+
newAP.passphrase = strdup(passphrase);
174173
if(!newAP.passphrase) {
175174
free(newAP.ssid);
176175
return false;
177176
}
178-
strcpy(newAP.passphrase, passphrase);
179177
}
180178

181179
APlist.push_back(newAP);

0 commit comments

Comments
 (0)