From 296166b1ca0d7f4155ab2ed47953e9f15574ccb1 Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Wed, 6 Dec 2023 12:17:08 +0530 Subject: [PATCH] [ESP32] Limit number of returned WiFi scan results to configured limit (#30780) Scan results are allocated on the heap and on a resource critical device where heap is less, this may fail if there are a lot of APs in the vicinity. --- src/platform/ESP32/NetworkCommissioningDriver.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/platform/ESP32/NetworkCommissioningDriver.cpp b/src/platform/ESP32/NetworkCommissioningDriver.cpp index 148704eeeeef2a..01d8c12c0acf66 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.cpp +++ b/src/platform/ESP32/NetworkCommissioningDriver.cpp @@ -309,6 +309,10 @@ void ESPWiFiDriver::OnScanWiFiNetworkDone() } return; } + + // Since this is the dynamic memory allocation, restrict it to a configured limit + ap_number = std::min(static_cast(CHIP_DEVICE_CONFIG_MAX_SCAN_NETWORKS_RESULTS), ap_number); + std::unique_ptr ap_buffer_ptr(new wifi_ap_record_t[ap_number]); if (ap_buffer_ptr == NULL) {