From 369b58b2d7653869bcae18f75e015eb54175b5ca Mon Sep 17 00:00:00 2001 From: navyasher Date: Wed, 8 Jul 2026 13:03:12 +0530 Subject: [PATCH] RDKB-65853: Fixing coverity issue 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: Navya_Sheregar@comcast.com --- lib/datapipeline/dppline.c | 32 ++++++++++++------- source/apps/harvester/wifi_harvester.c | 1 + source/core/services/vap_svc_mesh_ext.c | 13 ++++++-- source/dml/tr_181/ml/cosa_apis_util.c | 11 +++++-- .../linux/he_bus/src/he_bus_connection.c | 3 ++ source/services/mesh/wifi_service_mesh.c | 13 ++++++-- source/stats/wifi_associated_devices_msmt.c | 1 + source/webconfig/wifi_encoder.c | 28 ---------------- 8 files changed, 53 insertions(+), 49 deletions(-) diff --git a/lib/datapipeline/dppline.c b/lib/datapipeline/dppline.c index 4b7881915..b9de2d176 100644 --- a/lib/datapipeline/dppline.c +++ b/lib/datapipeline/dppline.c @@ -346,7 +346,11 @@ static bool dppline_copysts(dppline_stats_t * dst, void * sts) dst->u.survey.list = calloc(1, size); } else { - dst->u.survey.list = realloc(dst->u.survey.list, size); + void *tmp = realloc(dst->u.survey.list, size); + if (!tmp) { + return false; + } + dst->u.survey.list = tmp; memset(&dst->u.survey.list[dst->u.survey.qty], 0, sizeof(dpp_survey_record_t)); @@ -578,7 +582,7 @@ static bool dppline_copysts(dppline_stats_t * dst, void * sts) thermal_record != NULL; thermal_record = ds_dlist_inext(&result_iter)) { - thermal_size += (dst->u.device.thermal_qty + 1) * sizeof(dpp_device_thermal_record_t); + thermal_size = (dst->u.device.thermal_qty + 1) * sizeof(dpp_device_thermal_record_t); if (!dst->u.device.thermal_qty) { dst->u.device.thermal_list = calloc(1, thermal_size); @@ -693,31 +697,35 @@ static bool dppline_copysts(dppline_stats_t * dst, void * sts) dst->u.client_auth_fails.radio_type = report_data->radio_type; ds_dlist_iforeach(&report_data->bsses, bss_entry, bss_iter) { - const size_t bss_size = (dst->u.client_auth_fails.qty + 1) * sizeof(dpp_client_auth_fails_bss_t); + const size_t bss_size = (dst->u.client_auth_fails.qty + 1) * sizeof(dppline_client_auth_fails_bss_rec_t); if (!dst->u.client_auth_fails.qty) { dst->u.client_auth_fails.list = calloc(1, bss_size); } else { - dst->u.client_auth_fails.list = realloc(dst->u.client_auth_fails.list, bss_size); - if (!dst->u.client_auth_fails.list) - continue; + void *tmp = realloc(dst->u.client_auth_fails.list, bss_size); + if (!tmp) { + return false; + } + dst->u.client_auth_fails.list = tmp; - memset(&dst->u.client_auth_fails.list[dst->u.client_auth_fails.qty], 0, sizeof(dpp_client_auth_fails_bss_t)); + memset(&dst->u.client_auth_fails.list[dst->u.client_auth_fails.qty], 0, sizeof(dppline_client_auth_fails_bss_rec_t)); } STRSCPY_WARN(dst->u.client_auth_fails.list[dst->u.client_auth_fails.qty].if_name, bss_entry->if_name); ds_dlist_iforeach(&bss_entry->clients, client_entry, client_iter) { dppline_client_auth_fails_bss_rec_t *dst_bss = &dst->u.client_auth_fails.list[dst->u.client_auth_fails.qty]; - const size_t client_size = (dst_bss->qty + 1) * sizeof(dpp_client_auth_fails_client_t); + const size_t client_size = (dst_bss->qty + 1) * sizeof(dppline_client_auth_fails_client_rec_t); if (!dst_bss->qty) { dst_bss->list = calloc(1, client_size); } else { - dst_bss->list = realloc(dst_bss->list, client_size); - if (!dst_bss->list) - continue; + void *tmp = realloc(dst_bss->list, client_size); + if (!tmp) { + return false; + } + dst_bss->list = tmp; - memset(&dst_bss->list[dst_bss->qty], 0, sizeof(dpp_client_auth_fails_client_t)); + memset(&dst_bss->list[dst_bss->qty], 0, sizeof(dppline_client_auth_fails_client_rec_t)); } STRSCPY_WARN(dst_bss->list[dst_bss->qty].mac, client_entry->mac); diff --git a/source/apps/harvester/wifi_harvester.c b/source/apps/harvester/wifi_harvester.c index 0f41da3c2..de59fb554 100644 --- a/source/apps/harvester/wifi_harvester.c +++ b/source/apps/harvester/wifi_harvester.c @@ -593,6 +593,7 @@ void upload_single_client_msmt_data(sta_data_t *sta_info) } //Free up memory avro_value_decref(&adr); + avro_value_iface_decref(iface); avro_writer_free(writer); size += MAGIC_NUMBER_SIZE + SCHEMA_ID_LENGTH; diff --git a/source/core/services/vap_svc_mesh_ext.c b/source/core/services/vap_svc_mesh_ext.c index d2a74fcf3..68a6fe379 100644 --- a/source/core/services/vap_svc_mesh_ext.c +++ b/source/core/services/vap_svc_mesh_ext.c @@ -1843,10 +1843,17 @@ int process_ext_scan_results(vap_svc_t *svc, void *arg) scan_list = ext->candidates_list.scan_list; ext->candidates_list.scan_count = num; } else if (num) { - ext->candidates_list.scan_list = (bss_candidate_t *) realloc(ext->candidates_list.scan_list, + bss_candidate_t *tmp = (bss_candidate_t *) realloc(ext->candidates_list.scan_list, ((num + ext->candidates_list.scan_count) * sizeof(bss_candidate_t))); - scan_list = ext->candidates_list.scan_list + ext->candidates_list.scan_count; - ext->candidates_list.scan_count += num; + if (tmp == NULL) { + wifi_util_error_print(WIFI_CTRL, "%s:%d: realloc failed\n", __func__, __LINE__); + return 0; + } + else { + ext->candidates_list.scan_list = tmp; + scan_list = ext->candidates_list.scan_list + ext->candidates_list.scan_count; + ext->candidates_list.scan_count += num; + } } for (i = 0; i < num; i++) { diff --git a/source/dml/tr_181/ml/cosa_apis_util.c b/source/dml/tr_181/ml/cosa_apis_util.c index 1de1333eb..d9a8e67f8 100755 --- a/source/dml/tr_181/ml/cosa_apis_util.c +++ b/source/dml/tr_181/ml/cosa_apis_util.c @@ -1144,10 +1144,14 @@ int CosaUtilGetIpv6AddrInfo (char * ifname, ipv6_addr_info_t ** pp_info, int * p parsingResult=parseProcfileParams(procLine, &v6Details,ifname); if (parsingResult == 1) { - (*p_num)++; - *pp_info = realloc(*pp_info, *p_num * sizeof(ipv6_addr_info_t)); - if (!*pp_info) + const int new_num = (*p_num) + 1; + ipv6_addr_info_t *tmp = realloc(*pp_info, new_num * sizeof(ipv6_addr_info_t)); + if (!tmp) { + fclose(fp); return -1; + } + *pp_info = tmp; + *p_num = new_num; p_ai = &(*pp_info)[*p_num-1]; strncpy(p_ai->v6addr, v6Details.address6, sizeof(p_ai->v6addr)); @@ -1166,6 +1170,7 @@ int CosaUtilGetIpv6AddrInfo (char * ifname, ipv6_addr_info_t ** pp_info, int * p } } + fclose(fp); return 0; } diff --git a/source/platform/linux/he_bus/src/he_bus_connection.c b/source/platform/linux/he_bus/src/he_bus_connection.c index 196cd75d3..5ed78f835 100644 --- a/source/platform/linux/he_bus/src/he_bus_connection.c +++ b/source/platform/linux/he_bus/src/he_bus_connection.c @@ -437,6 +437,9 @@ int process_recv_unicast_connected_clients_data(he_bus_handle_t handle, hash_map he_bus_connection_info_t *temp_client = hash_map_remove(client_info_map, key); if (temp_client != NULL) { + if (temp_client->fd != SOCKET_INVALID_FD) { + close(temp_client->fd); + } he_bus_free(temp_client); } continue; diff --git a/source/services/mesh/wifi_service_mesh.c b/source/services/mesh/wifi_service_mesh.c index b99b49b37..a67daba26 100644 --- a/source/services/mesh/wifi_service_mesh.c +++ b/source/services/mesh/wifi_service_mesh.c @@ -1142,10 +1142,17 @@ int process_ext_scan_results(wifi_service_node_t *node, wifi_core_data_t *data) scan_list = ext->candidates_list.scan_list; ext->candidates_list.scan_count = num; } else if (num) { - ext->candidates_list.scan_list = (bss_candidate_t *) realloc(ext->candidates_list.scan_list, + bss_candidate_t *tmp = (bss_candidate_t *) realloc(ext->candidates_list.scan_list, ((num + ext->candidates_list.scan_count) * sizeof(bss_candidate_t))); - scan_list = ext->candidates_list.scan_list + ext->candidates_list.scan_count; - ext->candidates_list.scan_count += num; + if (tmp == NULL) { + wifi_util_error_print(WIFI_SERVICES, "%s:%d: realloc failed\n", __func__, __LINE__); + return 0; + } + else { + ext->candidates_list.scan_list = tmp; + scan_list = ext->candidates_list.scan_list + ext->candidates_list.scan_count; + ext->candidates_list.scan_count += num; + } } for (i = 0; i < num; i++) { diff --git a/source/stats/wifi_associated_devices_msmt.c b/source/stats/wifi_associated_devices_msmt.c index a7e7766df..0842246f3 100644 --- a/source/stats/wifi_associated_devices_msmt.c +++ b/source/stats/wifi_associated_devices_msmt.c @@ -585,6 +585,7 @@ void upload_associated_devices_msmt_data(bssid_data_t *bssid_info, sta_data_t *s //Free up memory avro_value_decref(&adr); + avro_value_iface_decref(iface); avro_writer_free(writer); size += MAGIC_NUMBER_SIZE + SCHEMA_ID_LENGTH; diff --git a/source/webconfig/wifi_encoder.c b/source/webconfig/wifi_encoder.c index c87f6ea29..5e6f143eb 100644 --- a/source/webconfig/wifi_encoder.c +++ b/source/webconfig/wifi_encoder.c @@ -2749,17 +2749,11 @@ webconfig_error_t encode_radio_channel_radio_params(wifi_provider_response_t *ch radio_chan_data_t *chan_data = chan_stats->stat_pointer; - radio_stats_obj = cJSON_CreateObject(); - if (radio_stats_obj == NULL) { - wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d json object creation failed\n", __func__, __LINE__); - return webconfig_error_encode; - } for (unsigned int count = 0; count < chan_stats->stat_array_size; count++) { radio_stats_obj = cJSON_CreateObject(); if (radio_stats_obj == NULL) { wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d: json create object failed\n", __func__, __LINE__); - cJSON_Delete(radio_stats_obj); return webconfig_error_encode; } cJSON_AddItemToArray(radio_stats, radio_stats_obj); @@ -2784,17 +2778,11 @@ webconfig_error_t encode_neighbor_radio_params(wifi_provider_response_t *neigh_s cJSON *neighbor_stats_obj; wifi_neighbor_ap2_t *neighbor_data = neigh_stats->stat_pointer; - neighbor_stats_obj = cJSON_CreateObject(); - if (neighbor_stats_obj == NULL) { - wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d json object creation failed\n", __func__, __LINE__); - return webconfig_error_encode; - } for (unsigned int count = 0; count < neigh_stats->stat_array_size; count++) { neighbor_stats_obj = cJSON_CreateObject(); if (neighbor_stats_obj == NULL) { wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d: json create object failed\n", __func__, __LINE__); - cJSON_Delete(neighbor_stats_obj); return webconfig_error_encode; } cJSON_AddItemToArray(neigh_stats_obj, neighbor_stats_obj); @@ -2895,17 +2883,11 @@ webconfig_error_t encode_assocdevice_params(wifi_provider_response_t *assoc_dev_ cJSON *client_stats_obj; sta_data_t *client_stats = assoc_dev_stats->stat_pointer; - client_stats_obj = cJSON_CreateObject(); - if (client_stats_obj == NULL) { - wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d json object creation failed\n", __func__, __LINE__); - return webconfig_error_encode; - } for (unsigned int count = 0; count < assoc_dev_stats->stat_array_size; count++) { client_stats_obj = cJSON_CreateObject(); if (client_stats_obj == NULL) { wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d json object creation failed\n", __func__, __LINE__); - cJSON_Delete(client_stats_obj); return webconfig_error_encode; } @@ -2954,11 +2936,6 @@ webconfig_error_t encode_radiodiag_params(wifi_provider_response_t *radiodiag_st cJSON *diag_obj; radio_data_t *diag_stats = radiodiag_stats->stat_pointer; - diag_obj = cJSON_CreateObject(); - if (diag_obj == NULL) { - wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d json object creation failed\n", __func__, __LINE__); - return webconfig_error_encode; - } for (unsigned int count = 0; count < radiodiag_stats->stat_array_size; count++) { diag_obj = cJSON_CreateObject(); @@ -3066,11 +3043,6 @@ webconfig_error_t encode_radio_temperature_params(wifi_provider_response_t *radi cJSON *temp_obj; radio_data_t *temp_stats = radiotemperature_stats->stat_pointer; - temp_obj = cJSON_CreateObject(); - if (temp_obj == NULL) { - wifi_util_error_print(WIFI_WEBCONFIG, "%s:%d json object creation failed\n", __func__, __LINE__); - return webconfig_error_encode; - } for (unsigned int count = 0; count < radiotemperature_stats->stat_array_size; count++) { temp_obj = cJSON_CreateObject();