@@ -53,6 +53,20 @@ esp_err_t set_esp_interface_dns(esp_interface_t interface, IPAddress main_dns=IP
53
53
esp_err_t set_esp_interface_ip (esp_interface_t interface, IPAddress local_ip=IPAddress(), IPAddress gateway=IPAddress(), IPAddress subnet=IPAddress());
54
54
static bool sta_config_equal (const wifi_config_t & lhs, const wifi_config_t & rhs);
55
55
56
+ static size_t _wifi_strncpy (char * dst, const char * src, size_t dst_len){
57
+ if (!dst || !src || !dst_len){
58
+ return 0 ;
59
+ }
60
+ size_t src_len = strlen (src);
61
+ if (src_len >= dst_len){
62
+ src_len = dst_len;
63
+ } else {
64
+ src_len += 1 ;
65
+ }
66
+ memcpy (dst, src, src_len);
67
+ return src_len;
68
+ }
69
+
56
70
57
71
/* *
58
72
* compare two STA configurations
@@ -82,10 +96,10 @@ static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL,
82
96
wifi_config->sta .ssid [0 ] = 0 ;
83
97
wifi_config->sta .password [0 ] = 0 ;
84
98
if (ssid != NULL && ssid[0 ] != 0 ){
85
- strncpy ((char *)wifi_config->sta .ssid , ssid, 32 );
99
+ _wifi_strncpy ((char *)wifi_config->sta .ssid , ssid, 32 );
86
100
if (password != NULL && password[0 ] != 0 ){
87
101
wifi_config->sta .threshold .authmode = WIFI_AUTH_WEP;
88
- strncpy ((char *)wifi_config->sta .password , password, 64 );
102
+ _wifi_strncpy ((char *)wifi_config->sta .password , password, 64 );
89
103
}
90
104
if (bssid != NULL ){
91
105
wifi_config->sta .bssid_set = 1 ;
@@ -161,11 +175,11 @@ wl_status_t WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_
161
175
162
176
wifi_config_t conf;
163
177
memset (&conf, 0 , sizeof (wifi_config_t ));
164
- strncpy (reinterpret_cast <char *>(conf.sta .ssid ), ssid, 32 );
178
+ _wifi_strncpy (reinterpret_cast <char *>(conf.sta .ssid ), ssid, 32 );
165
179
conf.sta .scan_method = WIFI_ALL_CHANNEL_SCAN; // force full scan to be able to choose the nearest / strongest AP
166
180
167
181
if (passphrase) {
168
- strncpy (reinterpret_cast <char *>(conf.sta .password ), passphrase, 64 );
182
+ _wifi_strncpy (reinterpret_cast <char *>(conf.sta .password ), passphrase, 64 );
169
183
}
170
184
171
185
wifi_config_t current_conf;
0 commit comments