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
project-chip#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.
  • Loading branch information
shubhamdp committed Dec 13, 2023
1 parent 5d8894c commit 296166b
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 @@ -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<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 296166b

Please sign in to comment.