@@ -97,14 +97,28 @@ void WiFi::startAp(const char* ssid, const char* pass, uint8_t channel) {
9797
9898 wifi_config_t cfg = {};
9999
100- if (strlen (pass) >= 8 ) {
101- snprintf ((char *)cfg.ap .password , 64 , " %s" , pass);
102- cfg.ap .authmode = WIFI_AUTH_WPA2_PSK;
103- } else {
100+ size_t pass_len = strlen (pass);
101+ if (pass_len < 8 ) {
104102 ESP_LOGE (TAG, " The WiFi password is too short, 8 characters required, leaving the WiFI open!" );
105103 cfg.ap .authmode = WIFI_AUTH_OPEN;
104+ } else {
105+ if (pass_len >= 64 ) {
106+ ESP_LOGE (TAG, " The WiFi password is too long, using first 63 characters only." );
107+ pass_len = 63 ;
108+ }
109+ memcpy (cfg.ap .password , pass, pass_len);
110+ cfg.ap .password [pass_len] = 0 ;
111+ cfg.ap .authmode = WIFI_AUTH_WPA2_PSK;
112+ }
113+
114+ size_t ssid_len = strlen (ssid);
115+ if (ssid_len >= 32 ) {
116+ ESP_LOGE (TAG, " The WiFi SSID password is too long, using first 31 characters only." );
117+ ssid_len = 31 ;
106118 }
107- snprintf ((char *)cfg.ap .ssid , 32 , " %s" , ssid);
119+ memcpy (cfg.ap .ssid , ssid, ssid_len);
120+ cfg.ap .ssid [ssid_len] = 0 ;
121+
108122 cfg.ap .channel = channel;
109123 cfg.ap .beacon_interval = 400 ;
110124 cfg.ap .max_connection = 4 ;
0 commit comments