RDKB-65777: Fixing coverity issue - #1256
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors parts of wifi_decoder.c to accommodate early-return decode macros by moving repetitive JSON decoding blocks into helper functions and introducing a wrapper/impl split for ANQP decoding to centralize cJSON lifetime management.
Changes:
- Split
decode_anqp_object()into a wrapper +decode_anqp_object_impl()sopassPointStatsis always cleaned up in one place. - Extract per-entry decoding into helpers for radio channel stats, neighbor stats, associated device stats, and radio diagnostic stats.
- Reorder some decoding/allocations to reduce leak risk when decode macros return early.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dd02bc8 to
5ecbc47
Compare
Reason for change: Fixing coverity issues. Test Procedure: Build should be successful and the regression test should also succeed Risks: Low Priority: P1 Signed-off-by: Velpula_Bharathi@comcast.com
5ecbc47 to
b6a65f1
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (5)
source/webconfig/wifi_decoder.c:5718
decode_radio_channel_radio_stats_object()does not handlesize == 0. On platforms wheremalloc(0)returns NULL, this will be treated as an allocation failure and incorrectly returnwebconfig_error_decodefor a valid empty stats array. Add an explicitsize == 0fast-path (similar to neighbor stats).
This issue also appears in the following locations of the same file:
- line 6316
- line 6378
chan_data = (radio_chan_data_t*) malloc(sizeof(radio_chan_data_t) * size);
if (chan_data == NULL) {
free(*chan_stats);
*chan_stats = NULL;
wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d Failed to allocate memory\n", __func__, __LINE__);
return webconfig_error_decode;
}
source/webconfig/wifi_decoder.c:6322
decode_radiodiag_stats_object()allocatesdiagnostic_dataeven when the array size is 0. Ifmalloc(0)returns NULL, this is treated as an error and the decode fails for an empty-but-valid stats array. Add asize == 0fast-path before the allocation.
diagnostic_data = (radio_data_t*) malloc(sizeof(radio_data_t) * size);
if (diagnostic_data == NULL) {
free(*diag_stats);
*diag_stats = NULL;
wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d Failed to allocate memory\n", __func__, __LINE__);
return webconfig_error_decode;
}
source/webconfig/wifi_decoder.c:6384
decode_radio_temperature_stats_object()allocatestemperature_dataeven when the array size is 0. Ifmalloc(0)returns NULL, this will be treated as an allocation failure and incorrectly returnwebconfig_error_decodefor a valid empty stats array. Add asize == 0fast-path before the allocation.
temperature_data = (radio_data_t*) malloc(sizeof(radio_data_t) * size);
if (temperature_data == NULL) {
free(*temp_stats);
*temp_stats = NULL;
wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d Failed to allocate memory\n", __func__, __LINE__);
return webconfig_error_decode;
}
source/webconfig/wifi_decoder.c:591
decode_anqp_object()allocates and builds the PassPointStats cJSON tree before validatinganqp/ii. This can produce misleading OOM errors on invalid input and does unnecessary work. Validate inputs up front and return early before any allocations.
webconfig_error_t decode_anqp_object(const cJSON *anqp, wifi_interworking_t *ii)
{
cJSON *passPointStats = cJSON_CreateObject();
if (passPointStats == NULL) {
wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d: Failed to create passPointStats object (OOM)\n", __func__, __LINE__);
return webconfig_error_decode;
}
source/webconfig/wifi_decoder.c:6075
decode_assocdev_stats_entry()decodes and assignscli_Retransmissionstwice, which is redundant and can mask future changes (e.g., if one decode is later modified). Remove the duplicate decode/assignment.
decode_param_integer(assoc_data, "cli_BytesReceived", param);
out->cli_BytesReceived = param->valuedouble;
decode_param_integer(assoc_data, "cli_Retransmissions", param);
out->cli_Retransmissions = param->valuedouble;
No description provided.