Skip to content

Commit

Permalink
[ESP32] Limit number of returned WiFi scan results to configured limit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shubhamdp committed Dec 4, 2023
1 parent 223c054 commit 3fce9f9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/platform/ESP32/NetworkCommissioningDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ void ESPWiFiDriver::OnScanWiFiNetworkDone()
mpScanCallback = nullptr;
return;
}

// Since this is the dynamic memory allocation, restrict it to a configured limit
ap_number = std::min(static_cast<uint16_t>(CHIP_DEVICE_CONFIG_MAX_SCAN_NETWORKS_RESULTS), ap_number);

std::unique_ptr<wifi_ap_record_t[]> ap_buffer_ptr(new wifi_ap_record_t[ap_number]);
if (ap_buffer_ptr == NULL)
{
Expand Down

0 comments on commit 3fce9f9

Please sign in to comment.