Skip to content

Commit c0df9b0

Browse files
committed
fix #386
1 parent ab03a26 commit c0df9b0

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp

+17-10
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ wl_status_t ESP8266WiFiMulti::run(void) {
7272

7373
WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan);
7474

75-
7675
bool known = false;
7776
for(uint32_t x = 0; x < APlist.size(); x++) {
7877
WifiAPlist_t entry = APlist[x];
@@ -152,7 +151,17 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
152151

153152
WifiAPlist_t newAP;
154153

155-
newAP.ssid = (char*) malloc(strlen(ssid));
154+
if(!ssid || strlen(ssid) > 31) {
155+
// fail SSID to long or missing!
156+
return false;
157+
}
158+
159+
if(passphrase && strlen(passphrase) > 63) {
160+
// fail passphrase to long!
161+
return false;
162+
}
163+
164+
newAP.ssid = (char*) malloc((strlen(ssid) + 1));
156165

157166
if(!newAP.ssid) {
158167
return false;
@@ -161,16 +170,14 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
161170
strcpy(newAP.ssid, ssid);
162171

163172
if(passphrase && *passphrase != 0x00) {
164-
newAP.passphrase = (char*) malloc(strlen(passphrase));
165-
}
166-
167-
if(!newAP.passphrase) {
168-
free(newAP.ssid);
169-
return false;
173+
newAP.passphrase = (char*) malloc((strlen(passphrase) + 1));
174+
if(!newAP.passphrase) {
175+
free(newAP.ssid);
176+
return false;
177+
}
178+
strcpy(newAP.passphrase, passphrase);
170179
}
171180

172-
strcpy(newAP.passphrase, passphrase);
173-
174181
APlist.push_back(newAP);
175182
return true;
176183
}

0 commit comments

Comments
 (0)