From 5261d7adf18b9b860a42f6612c77b6e1ef8d3941 Mon Sep 17 00:00:00 2001 From: Laukik Hase Date: Mon, 27 Dec 2021 10:36:56 +0530 Subject: [PATCH] wifi_prov_mgr: Added check for passphrase length in softAP scheme Closes https://github.com/espressif/esp-idf/issues/8063 --- components/wifi_provisioning/src/scheme_softap.c | 7 ++++++- examples/provisioning/wifi_prov_mgr/main/app_main.c | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/components/wifi_provisioning/src/scheme_softap.c b/components/wifi_provisioning/src/scheme_softap.c index 339472a0b1..5905f5d6ce 100644 --- a/components/wifi_provisioning/src/scheme_softap.c +++ b/components/wifi_provisioning/src/scheme_softap.c @@ -175,10 +175,15 @@ static esp_err_t set_config_service(void *config, const char *service_name, cons } wifi_prov_softap_config_t *softap_config = (wifi_prov_softap_config_t *) config; - strlcpy(softap_config->ssid, service_name, sizeof(softap_config->ssid)); if (service_key) { + const int service_key_len = strlen(service_key); + if (service_key_len < 8 || service_key_len >= sizeof(softap_config->password)) { + ESP_LOGE(TAG, "Incorrect passphrase length for softAP: %d (Expected: Min - 8, Max - 64)", service_key_len); + return ESP_ERR_INVALID_ARG; + } strlcpy(softap_config->password, service_key, sizeof(softap_config->password)); } + strlcpy(softap_config->ssid, service_name, sizeof(softap_config->ssid)); return ESP_OK; } diff --git a/examples/provisioning/wifi_prov_mgr/main/app_main.c b/examples/provisioning/wifi_prov_mgr/main/app_main.c index a5dd06973b..81925e2e7b 100644 --- a/examples/provisioning/wifi_prov_mgr/main/app_main.c +++ b/examples/provisioning/wifi_prov_mgr/main/app_main.c @@ -265,6 +265,7 @@ void app_main(void) /* What is the service key (could be NULL) * This translates to : * - Wi-Fi password when scheme is wifi_prov_scheme_softap + * (Minimum expected length: 8, maximum 64 for WPA2-PSK) * - simply ignored when scheme is wifi_prov_scheme_ble */ const char *service_key = NULL;