Skip to content

Commit c9d20b2

Browse files
committed
Additional fixes for 32-char ssid
1 parent 8e4258f commit c9d20b2

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFi.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,19 @@ void ESP8266WiFiClass::printDiag(Print& p) {
7272
struct station_config conf;
7373
wifi_station_get_config(&conf);
7474

75-
const char* ssid = reinterpret_cast<const char*>(conf.ssid);
75+
char ssid[33]; //ssid can be up to 32chars, => plus null term
76+
memcpy(ssid, conf.ssid, sizeof(conf.ssid));
77+
ssid[32] = 0; //nullterm in case of 32 char ssid
78+
7679
p.print("SSID (");
7780
p.print(strlen(ssid));
7881
p.print("): ");
7982
p.println(ssid);
8083

81-
const char* passphrase = reinterpret_cast<const char*>(conf.password);
84+
char passphrase[65];
85+
memcpy(passphrase, conf.password, sizeof(conf.password));
86+
passphrase[64] = 0;
87+
8288
p.print("Passphrase (");
8389
p.print(strlen(passphrase));
8490
p.print("): ");

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static bool sta_config_equal(const station_config& lhs, const station_config& rh
6262
* @return equal
6363
*/
6464
static bool sta_config_equal(const station_config& lhs, const station_config& rhs) {
65-
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0) {
65+
if(strncmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid), sizeof(lhs.ssid)) != 0) {
6666
return false;
6767
}
6868

libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,11 @@ String ESP8266WiFiScanClass::SSID(uint8_t i) {
186186
if(!it) {
187187
return "";
188188
}
189+
char tmp[33]; //ssid can be up to 32chars, => plus null term
190+
memcpy(tmp, it->ssid, sizeof(it->ssid));
191+
tmp[32] = 0; //nullterm in case of 32 char ssid
189192

190-
return String(reinterpret_cast<const char*>(it->ssid));
193+
return String(reinterpret_cast<const char*>(tmp));
191194
}
192195

193196

0 commit comments

Comments
 (0)