mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-22 09:06:27 +00:00
provisioning: use memcpy instead of strncpy for copying SSID
Per WiFi library requirement, SSID can be non-null terminated string if its length goes to 32 bytes (maximum). Use of strncpy in this case, along with compiler optimization level -O2 results in some warnings for potential use of non-null terminated strings. Fix here ensures use of memcpy to copy SSID string upto appropriate desired length. This helps to avoid compiler specific workaround flags added earlier. Closes https://github.com/espressif/esp-idf/issues/5866 Closes IDFGH-3983
This commit is contained in:
@@ -43,8 +43,11 @@ static esp_err_t start_wifi_ap(const char *ssid, const char *pass)
|
||||
},
|
||||
};
|
||||
|
||||
strncpy((char *) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
|
||||
wifi_config.ap.ssid_len = strnlen(ssid, sizeof(wifi_config.ap.ssid));
|
||||
/* SSID can be a non NULL terminated string if `ap.ssid_len` is specified
|
||||
* Hence, memcpy is used to support 32 bytes long SSID per 802.11 standard */
|
||||
const size_t ssid_len = strnlen(ssid, sizeof(wifi_config.ap.ssid));
|
||||
memcpy(wifi_config.ap.ssid, ssid, ssid_len);
|
||||
wifi_config.ap.ssid_len = ssid_len;
|
||||
|
||||
if (strlen(pass) == 0) {
|
||||
memset(wifi_config.ap.password, 0, sizeof(wifi_config.ap.password));
|
||||
|
Reference in New Issue
Block a user