Skip to content

Commit

Permalink
Merge branch 'cherry_pick/wifi_scan_fix' into 'v1.2-branch'
Browse files Browse the repository at this point in the history
[ESP32] Limit number of returned WiFi scan results to configured limit (project-chip#30780)

See merge request espressif/connectedhomeip!8
  • Loading branch information
dhrishi committed Mar 26, 2024
2 parents 6f57a17 + 3ad20f9 commit fa94232
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,8 @@ void ConnectivityManagerImpl::OnStationIPv6AddressAvailable(const ip_event_got_i
{
uint8_t dig1 = (station_mac[i] & 0xF0) >> 4;
uint8_t dig2 = station_mac[i] & 0x0F;
station_mac_str[2 * i] = dig1 > 9 ? ('A' + dig1 - 0xA) : ('0' + dig1);
station_mac_str[2 * i + 1] = dig2 > 9 ? ('A' + dig2 - 0xA) : ('0' + dig2);
station_mac_str[2 * i] = static_cast<char>(dig1 > 9 ? ('A' + dig1 - 0xA) : ('0' + dig1));
station_mac_str[2 * i + 1] = static_cast<char>(dig2 > 9 ? ('A' + dig2 - 0xA) : ('0' + dig2));
}
if (sEndpointQueueFilter.SetMdnsHostName(chip::CharSpan(station_mac_str)) == CHIP_NO_ERROR)
{
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ESP32/ESP32EndpointQueueFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ESP32EndpointQueueFilter : public EndpointQueueFilter
{
if (hostNameLowerCase[i] <= 'F' && hostNameLowerCase[i] >= 'A')
{
hostNameLowerCase[i] = 'a' + hostNameLowerCase[i] - 'A';
hostNameLowerCase[i] = static_cast<uint8_t>('a' + hostNameLowerCase[i] - 'A');
}
}
return PayloadContains(payload, ByteSpan(mHostNameBuffer)) || PayloadContains(payload, ByteSpan(hostNameLowerCase));
Expand Down
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 fa94232

Please sign in to comment.