Skip to content

Commit da46aee

Browse files
committed
addressing review comments
1 parent 6cf7ad2 commit da46aee

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <stdio.h>
2323
#include <stdlib.h>
2424
#include <string.h>
25+
2526
#if (SL_MATTER_GN_BUILD == 0)
2627
#include "sl_matter_wifi_config.h"
2728
#endif // SL_MATTER_GN_BUILD
@@ -42,7 +43,6 @@
4243
#include <lib/support/CHIPMemString.h>
4344
#include <lib/support/CodeUtils.h>
4445
#include <lib/support/logging/CHIPLogging.h>
45-
#include <platform/CHIPDeviceLayer.h>
4646

4747
extern "C" {
4848
#include "sl_net.h"
@@ -542,8 +542,11 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
542542
for (int idx = 0; idx < (int) scan_result->scan_count; idx++)
543543
{
544544
memset(&cur_scan_result, 0, sizeof(cur_scan_result));
545-
cur_scan_result.ssid_length = chip::min<size_t>(strnlen((char *) scan_result->scan_info[idx].ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination
546-
chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length, (char *) scan_result->scan_info[idx].ssid);
545+
546+
cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid,
547+
chip::min<size_t>(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH));
548+
chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length + 1, (char *) scan_result->scan_info[idx].ssid); // +1 for null termination
549+
547550
// if user has provided ssid, then check if the current scan result ssid matches the user provided ssid
548551
if (wfx_rsi.scan_ssid != NULL &&
549552
(strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, MIN(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) !=
@@ -601,7 +604,7 @@ static void wfx_rsi_save_ap_info(void) // translation
601604
sl_wifi_ssid_t ssid_arg;
602605
memset(&ssid_arg, 0, sizeof(ssid_arg));
603606
ssid_arg.length = wfx_rsi.sec.ssid_length;
604-
memcpy((char *) &ssid_arg.value[0], wfx_rsi.sec.ssid, ssid_arg.length);
607+
chip::Platform::CopyString((char *) &ssid_arg.value[0], ssid_arg.length + 1, wfx_rsi.sec.ssid); // +1 for null termination
605608
sl_wifi_set_scan_callback(scan_callback_handler, NULL);
606609
scan_results_complete = false;
607610
#ifndef EXP_BOARD

examples/platform/silabs/efr32/rs911x/rsi_if.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,9 @@ void ProcessEvent(WfxEvent_t inEvent)
755755
scan = &scan_rsp.scan_info[x];
756756
// clear structure and calculate size of SSID
757757
memset(&ap, 0, sizeof(ap));
758-
ap.ssid_length = chip::min<size_t>(strnlen(ap.ssid, WFX_MAX_SSID_LENGTH) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination
759-
chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast<char *>(scan->ssid));
758+
ap.ssid_length =
759+
strnlen(reinterpret_cast<char *>(scan->ssid), chip::min<size_t>(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH));
760+
chip::Platform::CopyString(ap.ssid, ap.ssid_length + 1, reinterpret_cast<char *>(scan->ssid)); // +1 for null termination
760761

761762
// check if the scanned ssid is the one we are looking for
762763
if (wfx_rsi.scan_ssid_length != 0 && strncmp(wfx_rsi.scan_ssid, ap.ssid, WFX_MAX_SSID_LENGTH) != CMP_SUCCESS)

examples/platform/silabs/efr32/wf200/host_if.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,8 @@ int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap)
736736
{
737737
int32_t signal_strength;
738738

739-
ap->ssid_length = chip::min<size_t>(strlen(ap_info.ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination
740-
chip::Platform::CopyString(ap->ssid, ap->ssid_length, ap_info.ssid);
739+
ap->ssid_length = strnlen(ap_info.ssid, chip::min<size_t>(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH));
740+
chip::Platform::CopyString(ap->ssid, ap->ssid_length + 1, ap_info.ssid); // +1 for null termination
741741
memcpy(ap->bssid, ap_info.bssid, sizeof(ap_info.bssid));
742742
ap->security = ap_info.security;
743743
ap->chan = ap_info.chan;
@@ -1184,10 +1184,10 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
11841184
VerifyOrReturnError(scan_cb != nullptr, false);
11851185
if (ssid)
11861186
{
1187-
scan_ssid_length = chip::min<size_t>(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination
1188-
scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(scan_ssid_length));
1187+
scan_ssid_length = strnlen(ssid, chip::min<size_t>(sizeof(ssid), WFX_MAX_SSID_LENGTH));
1188+
scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(scan_ssid_length + 1));
11891189
VerifyOrReturnError(scan_ssid != nullptr, false);
1190-
Platform::CopyString(scan_ssid, scan_ssid_length, ssid);
1190+
Platform::CopyString(scan_ssid, scan_ssid_length + 1, ssid);
11911191
}
11921192
scan_cb = callback;
11931193
xEventGroupSetBits(sl_wfx_event_group, SL_WFX_SCAN_START);

examples/platform/silabs/wifi/wfx_rsi_host.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <lib/support/CHIPMemString.h>
2929
#include <lib/support/CodeUtils.h>
3030
#include <lib/support/logging/CHIPLogging.h>
31+
3132
#include "wfx_host_events.h"
3233
#include "wfx_rsi.h"
3334

@@ -368,10 +369,11 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
368369
wfx_rsi.scan_cb = callback;
369370
// if SSID is provided to scan only that SSID
370371
if(ssid) {
371-
wfx_rsi.scan_ssid_length = chip::min<size_t>(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination
372-
wfx_rsi.scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length));
372+
// wfx_rsi.scan_ssid_length = chip::min<size_t>(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination
373+
wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min<size_t>(sizeof(ssid), WFX_MAX_SSID_LENGTH));
374+
wfx_rsi.scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length + 1));
373375
VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false);
374-
chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid);
376+
chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length + 1, ssid);
375377
}
376378
WfxEvent_t event;
377379
event.eventType = WFX_EVT_SCAN;

0 commit comments

Comments
 (0)