Skip to content

Commit bd433ef

Browse files
committed
fix: snprintf format warning
1 parent 8481b79 commit bd433ef

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"maintainer": true
1515
}
1616
],
17-
"version": "14.0.2",
17+
"version": "14.0.3",
1818
"frameworks": ["espidf", "arduino"],
1919
"platforms": "espressif32"
2020
}

src/rbwifi_netif.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)