diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp index c65a97ea3a..47c9aa51cd 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp @@ -545,11 +545,12 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid, chip::min(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH)); - chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length, (char *) scan_result->scan_info[idx].ssid); + // cur_scan_result.ssid is of size WFX_MAX_SSID_LENGTH+1, we are safe with the cur_scan_result.ssid_length calculated above + chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length + 1, (char *) scan_result->scan_info[idx].ssid); // +1 for null termination // if user has provided ssid, then check if the current scan result ssid matches the user provided ssid if (wfx_rsi.scan_ssid != NULL && - (strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, MIN(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) == + (strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, MIN(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) != CMP_SUCCESS)) { continue; @@ -603,8 +604,8 @@ static void wfx_rsi_save_ap_info(void) // translation #endif sl_wifi_ssid_t ssid_arg; memset(&ssid_arg, 0, sizeof(ssid_arg)); - ssid_arg.length = wfx_rsi.sec.ssid_length; - chip::Platform::CopyString((char *) &ssid_arg.value[0], ssid_arg.length, wfx_rsi.sec.ssid); + ssid_arg.length = chip::min(wfx_rsi.sec.ssid_length, sizeof(ssid_arg.value) - 1); + chip::Platform::CopyString((char *) &ssid_arg.value[0], ssid_arg.length + 1, wfx_rsi.sec.ssid); // +1 for null termination sl_wifi_set_scan_callback(scan_callback_handler, NULL); scan_results_complete = false; #ifndef EXP_BOARD diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp index cedfc05cd5..4510978329 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp @@ -757,7 +757,8 @@ void ProcessEvent(WfxEvent_t inEvent) memset(&ap, 0, sizeof(ap)); ap.ssid_length = strnlen(reinterpret_cast(scan->ssid), chip::min(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH)); - chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast(scan->ssid)); + // ap.ssid is of size WFX_MAX_SSID_LENGTH+1, we are safe with the ap.ssid_length calculated above + chip::Platform::CopyString(ap.ssid, ap.ssid_length + 1, reinterpret_cast(scan->ssid)); // +1 for null termination // check if the scanned ssid is the one we are looking for if (wfx_rsi.scan_ssid_length != 0 && strncmp(wfx_rsi.scan_ssid, ap.ssid, WFX_MAX_SSID_LENGTH) != CMP_SUCCESS) diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/examples/platform/silabs/efr32/wf200/host_if.cpp index 044ecc6e97..f1686b0aa8 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/examples/platform/silabs/efr32/wf200/host_if.cpp @@ -737,7 +737,8 @@ int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap) int32_t signal_strength; ap->ssid_length = strnlen(ap_info.ssid, chip::min(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH)); - chip::Platform::CopyString(ap->ssid, ap->ssid_length, ap_info.ssid); + // ap->ssid is of size WFX_MAX_SSID_LENGTH+1, we are safe with the ap->ssid_length calculated above + chip::Platform::CopyString(ap->ssid, ap->ssid_length + 1, ap_info.ssid); // +1 for null termination memcpy(ap->bssid, ap_info.bssid, sizeof(ap_info.bssid)); ap->security = ap_info.security; ap->chan = ap_info.chan; @@ -1184,10 +1185,10 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) VerifyOrReturnError(scan_cb != nullptr, false); if (ssid) { - scan_ssid_length = strnlen(ssid, WFX_MAX_SSID_LENGTH); - scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(scan_ssid_length)); + scan_ssid_length = strnlen(ssid, chip::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); + scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(scan_ssid_length + 1)); VerifyOrReturnError(scan_ssid != nullptr, false); - Platform::CopyString(scan_ssid, scan_ssid_length, ssid); + Platform::CopyString(scan_ssid, scan_ssid_length + 1, ssid); } scan_cb = callback; xEventGroupSetBits(sl_wfx_event_group, SL_WFX_SCAN_START); diff --git a/examples/platform/silabs/wifi/wfx_rsi_host.cpp b/examples/platform/silabs/wifi/wfx_rsi_host.cpp index 130d9c90d1..df64e915d4 100644 --- a/examples/platform/silabs/wifi/wfx_rsi_host.cpp +++ b/examples/platform/silabs/wifi/wfx_rsi_host.cpp @@ -365,15 +365,15 @@ int32_t wfx_reset_counts(void) bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) { // check if already in progress - VerifyOrReturnError(wfx_rsi.scan_cb != nullptr, false); + VerifyOrReturnError(wfx_rsi.scan_cb == nullptr, false); wfx_rsi.scan_cb = callback; - - VerifyOrReturnError(ssid != nullptr, false); - wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); - wfx_rsi.scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length)); - VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false); - chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid); - + // if SSID is provided to scan only that SSID + if(ssid) { + wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); + wfx_rsi.scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length + 1)); + VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false); + chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length + 1, ssid); + } WfxEvent_t event; event.eventType = WFX_EVT_SCAN; WfxPostEvent(&event);