Skip to content

RDKB-65777: Fixing coverity issue - #1256

Open
bharathivelp wants to merge 1 commit into
rdkcentral:developfrom
bharathivelp:fix/macroearly
Open

RDKB-65777: Fixing coverity issue#1256
bharathivelp wants to merge 1 commit into
rdkcentral:developfrom
bharathivelp:fix/macroearly

Conversation

@bharathivelp

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 10, 2026 12:39
@bharathivelp
bharathivelp requested a review from a team as a code owner July 10, 2026 12:39
@bharathivelp
bharathivelp marked this pull request as draft July 10, 2026 12:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() so passPointStats is 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.

Comment thread source/webconfig/wifi_decoder.c
Comment thread source/webconfig/wifi_decoder.c
Comment thread source/webconfig/wifi_decoder.c
Comment thread source/webconfig/wifi_decoder.c
@bharathivelp
bharathivelp force-pushed the fix/macroearly branch 2 times, most recently from dd02bc8 to 5ecbc47 Compare July 23, 2026 11:29
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
@bharathivelp bharathivelp changed the title macro_early_return RDKB-65777: Fixing coverity issue Jul 29, 2026
@bharathivelp
bharathivelp marked this pull request as ready for review July 29, 2026 06:13
Copilot AI review requested due to automatic review settings July 29, 2026 06:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 handle size == 0. On platforms where malloc(0) returns NULL, this will be treated as an allocation failure and incorrectly return webconfig_error_decode for a valid empty stats array. Add an explicit size == 0 fast-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() allocates diagnostic_data even when the array size is 0. If malloc(0) returns NULL, this is treated as an error and the decode fails for an empty-but-valid stats array. Add a size == 0 fast-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() allocates temperature_data even when the array size is 0. If malloc(0) returns NULL, this will be treated as an allocation failure and incorrectly return webconfig_error_decode for a valid empty stats array. Add a size == 0 fast-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 validating anqp/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 assigns cli_Retransmissions twice, 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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants