@@ -62,7 +62,7 @@ static bool sta_config_equal(const station_config& lhs, const station_config& rh
62
62
* @return equal
63
63
*/
64
64
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 ) {
66
66
return false ;
67
67
}
68
68
@@ -108,7 +108,7 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
108
108
return WL_CONNECT_FAILED;
109
109
}
110
110
111
- if (!ssid || *ssid == 0x00 || strlen (ssid) > 31 ) {
111
+ if (!ssid || *ssid == 0x00 || strlen (ssid) > 32 ) {
112
112
// fail SSID too long or missing!
113
113
return WL_CONNECT_FAILED;
114
114
}
@@ -119,10 +119,12 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
119
119
}
120
120
121
121
struct station_config conf;
122
- strcpy (reinterpret_cast <char *>(conf.ssid ), ssid);
122
+ if (strlen (ssid) == 32 )
123
+ memcpy (reinterpret_cast <char *>(conf.ssid ), ssid, 32 ); // copied in without null term
124
+ else
125
+ strcpy (reinterpret_cast <char *>(conf.ssid ), ssid);
123
126
124
127
conf.threshold .authmode = AUTH_OPEN;
125
-
126
128
if (passphrase) {
127
129
conf.threshold .authmode = _useInsecureWEP ? AUTH_WEP : AUTH_WPA_PSK;
128
130
if (strlen (passphrase) == 64 ) // it's not a passphrase, is the PSK, which is copied into conf.password without null term
@@ -524,7 +526,10 @@ wl_status_t ESP8266WiFiSTAClass::status() {
524
526
String ESP8266WiFiSTAClass::SSID () const {
525
527
struct station_config conf;
526
528
wifi_station_get_config (&conf);
527
- return String (reinterpret_cast <char *>(conf.ssid ));
529
+ char tmp[33 ]; // ssid can be up to 32chars, => plus null term
530
+ memcpy (tmp, conf.ssid , sizeof (conf.ssid ));
531
+ tmp[32 ] = 0 ; // nullterm in case of 32 char ssid
532
+ return String (reinterpret_cast <char *>(tmp));
528
533
}
529
534
530
535
/* *
0 commit comments