From 6111476addc8508cd5fe2091f7bf6d0ebd600b12 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav <69809379+jadhavrohit924@users.noreply.github.com> Date: Tue, 8 Mar 2022 20:25:37 +0530 Subject: [PATCH] [ESP32] Added check for copying ssid and pass (#15958) --- src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp index 85e739e58cf524..6b683d916a44e0 100644 --- a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp +++ b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp @@ -402,8 +402,10 @@ CHIP_ERROR ConnectivityManagerImpl::InitWiFi() // Set a default station configuration. wifi_config_t wifiConfig; memset(&wifiConfig, 0, sizeof(wifiConfig)); - memcpy(wifiConfig.sta.ssid, CONFIG_DEFAULT_WIFI_SSID, strlen(CONFIG_DEFAULT_WIFI_SSID) + 1); - memcpy(wifiConfig.sta.password, CONFIG_DEFAULT_WIFI_PASSWORD, strlen(CONFIG_DEFAULT_WIFI_PASSWORD) + 1); + memcpy(wifiConfig.sta.ssid, CONFIG_DEFAULT_WIFI_SSID, + std::min(sizeof(wifiConfig.sta.ssid), strlen(CONFIG_DEFAULT_WIFI_SSID))); + memcpy(wifiConfig.sta.password, CONFIG_DEFAULT_WIFI_PASSWORD, + std::min(sizeof(wifiConfig.sta.password), strlen(CONFIG_DEFAULT_WIFI_PASSWORD))); wifiConfig.sta.scan_method = WIFI_ALL_CHANNEL_SCAN; wifiConfig.sta.sort_method = WIFI_CONNECT_AP_BY_SIGNAL; esp_err_t err = esp_wifi_set_config(WIFI_IF_STA, &wifiConfig);