From 23340811be39b6474f1b0e198fbe332644555a71 Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk <66371704+kkasperczyk-no@users.noreply.github.com> Date: Mon, 8 May 2023 19:35:15 +0200 Subject: [PATCH] [nrfconnect] Fixed using temporary buffer in GetWiFiInfo (#26278) In GetWiFiInfo there is temporary buffer used for ByteSpan initialization, that then may be used out of this call scope. Replaced unnecessarily used ByteSpan with simple uint8_t array. --- src/platform/nrfconnect/DiagnosticDataProviderImplNrf.cpp | 6 +++++- src/platform/nrfconnect/wifi/WiFiManager.cpp | 5 +---- src/platform/nrfconnect/wifi/WiFiManager.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/platform/nrfconnect/DiagnosticDataProviderImplNrf.cpp b/src/platform/nrfconnect/DiagnosticDataProviderImplNrf.cpp index 0130d432bfda69..e71e6e392c9edd 100644 --- a/src/platform/nrfconnect/DiagnosticDataProviderImplNrf.cpp +++ b/src/platform/nrfconnect/DiagnosticDataProviderImplNrf.cpp @@ -46,8 +46,12 @@ CHIP_ERROR DiagnosticDataProviderImplNrf::GetWiFiBssId(MutableByteSpan & value) { WiFiManager::WiFiInfo info; ReturnErrorOnFailure(WiFiManager::Instance().GetWiFiInfo(info)); + ReturnErrorCodeIf(sizeof(info.mBssId) >= value.size(), CHIP_ERROR_BUFFER_TOO_SMALL); - return CopySpanToMutableSpan(info.mBssId, value); + memcpy(value.data(), info.mBssId, sizeof(info.mBssId)); + value.reduce_size(sizeof(info.mBssId)); + + return CHIP_NO_ERROR; } CHIP_ERROR diff --git a/src/platform/nrfconnect/wifi/WiFiManager.cpp b/src/platform/nrfconnect/wifi/WiFiManager.cpp index f8a8f63fdd166f..d8e60bada951ec 100644 --- a/src/platform/nrfconnect/wifi/WiFiManager.cpp +++ b/src/platform/nrfconnect/wifi/WiFiManager.cpp @@ -286,16 +286,13 @@ CHIP_ERROR WiFiManager::GetWiFiInfo(WiFiInfo & info) const if (status.state >= WIFI_STATE_ASSOCIATED) { - uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; - net_sprint_ll_addr_buf(reinterpret_cast(status.bssid), WIFI_MAC_ADDR_LEN, - reinterpret_cast(mac_string_buf), sizeof(mac_string_buf)); - info.mBssId = ByteSpan(mac_string_buf, sizeof(mac_string_buf)); info.mSecurityType = MapToMatterSecurityType(status.security); info.mWiFiVersion = MapToMatterWiFiVersionCode(status.link_mode); info.mRssi = static_cast(status.rssi); info.mChannel = static_cast(status.channel); info.mSsidLen = status.ssid_len; memcpy(info.mSsid, status.ssid, status.ssid_len); + memcpy(info.mBssId, status.bssid, sizeof(status.bssid)); return CHIP_NO_ERROR; } diff --git a/src/platform/nrfconnect/wifi/WiFiManager.h b/src/platform/nrfconnect/wifi/WiFiManager.h index 2e1b86e94b0a8e..880ab4c4ba2a50 100644 --- a/src/platform/nrfconnect/wifi/WiFiManager.h +++ b/src/platform/nrfconnect/wifi/WiFiManager.h @@ -127,7 +127,7 @@ class WiFiManager struct WiFiInfo { - ByteSpan mBssId{}; + uint8_t mBssId[DeviceLayer::Internal::kWiFiBSSIDLength]; app::Clusters::WiFiNetworkDiagnostics::SecurityTypeEnum mSecurityType{}; app::Clusters::WiFiNetworkDiagnostics::WiFiVersionEnum mWiFiVersion{}; uint16_t mChannel{};