Skip to content

Commit ee43b72

Browse files
RDKBWIFI-203: wifi_ctrl_wifiapi_handlers: add null check for dev_array (rdkcentral#696)
The changes in this PR were automatically generated by the Permanence AI Coder and reviewed by @fwph. This change moves the deallocation of dev_array outside of the for loop to prvent a null pointer dereference when num_devs > 1. In addition, it adds a null check for dev_array after the call to wifi_getApAssociatedDeviceDiagnosticResult3. If dev_array is null, an error message is written to result_buf and the function returns early to prevent null pointer deferecnces. on-behalf-of: @permanence-ai <[email protected]>
1 parent 465af14 commit ee43b72

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

source/core/wifi_ctrl_wifiapi_handlers.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,10 @@ static void wifiapi_handle_get_ApAssocDeviceDiagnosticResult(char **args, unsign
622622
}
623623
return;
624624
}
625+
if (dev_array == NULL) {
626+
snprintf(result_buf, result_buf_size, "Error: dev_array is NULL\n");
627+
return;
628+
}
625629
char* to_sta_key(uint8_t *mac_address, sta_key_t sta_key) {
626630
snprintf(sta_key, STA_KEY_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
627631
mac_address[0], mac_address[1], mac_address[2],
@@ -660,11 +664,11 @@ static void wifiapi_handle_get_ApAssocDeviceDiagnosticResult(char **args, unsign
660664
dev_array[i].cli_MultipleRetryCount, dev_array[i].cli_MaxDownlinkRate,
661665
dev_array[i].cli_MaxUplinkRate, dev_array[i].cli_activeNumSpatialStreams,
662666
dev_array[i].cli_TxFrames, dev_array[i].cli_RxRetries, dev_array[i].cli_RxErrors);
667+
}
663668
if (dev_array != NULL) {
664669
free(dev_array);
665670
dev_array = NULL;
666671
}
667-
}
668672
}
669673

670674
void process_wifiapi_command(char *command, unsigned int len)

0 commit comments

Comments
 (0)