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:
Mahavir Jain
2020-09-15 12:17:52 +05:30
parent 1a1e1911f9
commit 6a3d50c952
8 changed files with 37 additions and 22 deletions

View File

@@ -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));