From b0b73af914c9b63315037f6f24321de193065ead Mon Sep 17 00:00:00 2001 From: Shimmy Balsam Date: Tue, 11 Jul 2023 15:07:20 +0300 Subject: [PATCH 1/2] CORE: coverity fixes --- src/components/tl/sharp/tl_sharp_context.c | 2 ++ src/core/ucc_coll.c | 2 +- src/core/ucc_context.c | 5 +++++ src/core/ucc_lib.c | 5 ++++- src/utils/ucc_coll_utils.c | 13 ++++++++----- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/components/tl/sharp/tl_sharp_context.c b/src/components/tl/sharp/tl_sharp_context.c index 5793bfcade..7430eeb067 100644 --- a/src/components/tl/sharp/tl_sharp_context.c +++ b/src/components/tl/sharp/tl_sharp_context.c @@ -428,6 +428,7 @@ ucc_status_t ucc_tl_sharp_context_create_epilog(ucc_base_context_t *context) return UCC_OK; } + memset(&set.map, 0, sizeof(ucc_ep_map_t)); set.map.type = UCC_EP_MAP_FULL; set.myrank = UCC_TL_CTX_OOB(sharp_ctx).oob_ep; set.map.ep_num = UCC_TL_CTX_OOB(sharp_ctx).n_oob_eps; @@ -447,6 +448,7 @@ ucc_status_t ucc_tl_sharp_context_create_epilog(ucc_base_context_t *context) status = ucc_tl_sharp_context_init(sharp_ctx, &sharp_ctx->sharp_context, &sharp_ctx->oob_ctx, topo); if (status != UCC_OK) { + ucc_topo_cleanup(topo); return status; } diff --git a/src/core/ucc_coll.c b/src/core/ucc_coll.c index 558ca6ef25..cb787fe6aa 100644 --- a/src/core/ucc_coll.c +++ b/src/core/ucc_coll.c @@ -194,7 +194,7 @@ UCC_CORE_PROFILE_FUNC(ucc_status_t, ucc_collective_init, } /* TO discuss: maybe we want to pass around user pointer ? */ - op_args.mask = 0; + memset(&op_args, 0, sizeof(ucc_base_coll_args_t)); memcpy(&op_args.args, coll_args, sizeof(ucc_coll_args_t)); op_args.team = team; diff --git a/src/core/ucc_context.c b/src/core/ucc_context.c index 1965e46d10..f86f234015 100644 --- a/src/core/ucc_context.c +++ b/src/core/ucc_context.c @@ -392,6 +392,7 @@ static ucc_status_t ucc_create_tl_contexts(ucc_context_t *ctx, tl_lib->iface->super.name); continue; } + // coverity[overrun-buffer-val:FALSE] status = tl_lib->iface->context.create( &b_params, &ctx_config->tl_cfgs[i]->super.super, &b_ctx); if (UCC_OK != status) { @@ -645,6 +646,7 @@ ucc_status_t ucc_context_create_proc_info(ucc_lib_h lib, ctx->cl_flags = 0; for (i = 0; i < num_cls; i++) { cl_lib = config->cl_cfgs[i]->cl_lib; + // coverity[overrun-buffer-val:FALSE] status = cl_lib->iface->context.create( &b_params, &config->cl_cfgs[i]->super.super, &b_ctx); if (UCC_OK != status) { @@ -746,6 +748,8 @@ ucc_status_t ucc_context_create_proc_info(ucc_lib_h lib, ucc_debug("TL UCP context is not available, " "service team can not be created"); } else { + memset(&t_params.map, 0, sizeof(ucc_ep_map_t)); + memset(&t_params.params, 0, sizeof(ucc_team_params_t)); t_params.params.mask = UCC_TEAM_PARAM_FIELD_EP | UCC_TEAM_PARAM_FIELD_EP_RANGE | UCC_TEAM_PARAM_FIELD_OOB; @@ -1070,6 +1074,7 @@ ucc_status_t ucc_context_get_attr(ucc_context_t *context, ucc_base_ctx_attr_t attr; ucc_tl_lib_t * tl_lib; + memset(&attr.attr, 0, sizeof(ucc_context_attr_t)); attr.attr.mask = UCC_CONTEXT_ATTR_FIELD_WORK_BUFFER_SIZE; attr.attr.global_work_buffer_size = 0; for (i = 0; i < context->n_tl_ctx; i++) { diff --git a/src/core/ucc_lib.c b/src/core/ucc_lib.c index 01731eb46d..6f909eda08 100644 --- a/src/core/ucc_lib.c +++ b/src/core/ucc_lib.c @@ -90,7 +90,7 @@ static ucc_status_t ucc_cl_lib_init(const ucc_lib_params_t *user_params, } lib->cl_attrs = (ucc_cl_lib_attr_t *) - ucc_malloc(sizeof(ucc_cl_lib_attr_t) * n_cls, "cl_attrs"); + ucc_calloc(n_cls, sizeof(ucc_cl_lib_attr_t), "cl_attrs"); if (!lib->cl_attrs) { ucc_error("failed to allocate %zd bytes for cl_attrs", sizeof(ucc_cl_lib_attr_t) * n_cls); @@ -103,6 +103,7 @@ static ucc_status_t ucc_cl_lib_init(const ucc_lib_params_t *user_params, params.mask |= UCC_LIB_PARAM_FIELD_THREAD_MODE; params.thread_mode = UCC_THREAD_SINGLE; } + memset(&b_params, 0, sizeof(ucc_base_lib_params_t)); ucc_copy_lib_params(&b_params.params, ¶ms); ucc_assert(config->cls.count >= 1); lib->specific_cls_requested = (0 == ucc_cl_requested(config, UCC_CL_ALL)); @@ -122,6 +123,7 @@ static ucc_status_t ucc_cl_lib_init(const ucc_lib_params_t *user_params, cl_iface->super.name); goto error_cfg_read; } + // coverity[overrun-buffer-val:FALSE] status = cl_iface->lib.init(&b_params, &cl_config->super.super, &b_lib); if (UCC_OK != status) { if (lib->specific_cls_requested) { @@ -271,6 +273,7 @@ static ucc_status_t ucc_tl_lib_init(const ucc_lib_params_t *user_params, tl_iface->super.name); continue; } + // coverity[overrun-buffer-val:FALSE] status = tl_iface->lib.init(&b_params, &tl_config->super.super, &b_lib); ucc_base_config_release(&tl_config->super.super); diff --git a/src/utils/ucc_coll_utils.c b/src/utils/ucc_coll_utils.c index 14a7785fbe..ac680e819b 100644 --- a/src/utils/ucc_coll_utils.c +++ b/src/utils/ucc_coll_utils.c @@ -270,6 +270,7 @@ ucc_ep_map_from_array_generic(void **array, ucc_rank_t size, int64_t stride; ucc_rank_t i; + memset(&map, 0, sizeof(ucc_ep_map_t)); map.ep_num = size; if (size > 1) { /* try to detect strided pattern */ @@ -550,13 +551,15 @@ void ucc_coll_str(const ucc_coll_task_t *task, char *str, size_t len, if (task->team->context->lib->log_component.name[0] == 'C') { /* it's not CL BASIC task */ - strncpy(cl_info, task->team->context->lib->log_component.name, - sizeof(cl_info)); + ucc_strncpy_safe(cl_info, + task->team->context->lib->log_component.name, + sizeof(cl_info)); ucc_coll_task_components_str(task, tl_info, &tl_info_len); } else { - strncpy(cl_info, "CL_BASIC", sizeof(cl_info)); - strncpy(tl_info , task->team->context->lib->log_component.name, - sizeof(tl_info)); + ucc_strncpy_safe(cl_info, "CL_BASIC", sizeof(cl_info)); + ucc_strncpy_safe(tl_info, + task->team->context->lib->log_component.name, + sizeof(tl_info)); } ucc_coll_args_str(&task->bargs.args, team->rank, team->size, str, len); rc = ucc_snprintf_safe(task_info, sizeof(task_info), From 9250c51018b679173dc92044b70cbadb18562b9a Mon Sep 17 00:00:00 2001 From: Shimmy Balsam Date: Mon, 17 Jul 2023 11:17:25 +0300 Subject: [PATCH 2/2] REVIEW: minor fixes --- src/core/ucc_coll.c | 3 +-- src/utils/ucc_coll_utils.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/ucc_coll.c b/src/core/ucc_coll.c index cb787fe6aa..755b1deb01 100644 --- a/src/core/ucc_coll.c +++ b/src/core/ucc_coll.c @@ -161,8 +161,8 @@ UCC_CORE_PROFILE_FUNC(ucc_status_t, ucc_collective_init, (coll_args, request, team), ucc_coll_args_t *coll_args, ucc_coll_req_h *request, ucc_team_h team) { + ucc_base_coll_args_t op_args = {0}; ucc_coll_task_t *task; - ucc_base_coll_args_t op_args; ucc_status_t status; ucc_ee_executor_params_t params; ucc_memory_type_t coll_mem_type; @@ -194,7 +194,6 @@ UCC_CORE_PROFILE_FUNC(ucc_status_t, ucc_collective_init, } /* TO discuss: maybe we want to pass around user pointer ? */ - memset(&op_args, 0, sizeof(ucc_base_coll_args_t)); memcpy(&op_args.args, coll_args, sizeof(ucc_coll_args_t)); op_args.team = team; diff --git a/src/utils/ucc_coll_utils.c b/src/utils/ucc_coll_utils.c index ac680e819b..e9d915f74e 100644 --- a/src/utils/ucc_coll_utils.c +++ b/src/utils/ucc_coll_utils.c @@ -266,11 +266,10 @@ ucc_ep_map_from_array_generic(void **array, ucc_rank_t size, ucc_rank_t full_size, int need_free, int is64) { int is_const_stride = 0; - ucc_ep_map_t map; + ucc_ep_map_t map = {0}; int64_t stride; ucc_rank_t i; - memset(&map, 0, sizeof(ucc_ep_map_t)); map.ep_num = size; if (size > 1) { /* try to detect strided pattern */