From ab0d7d0f5082db10a379e302b887b98ab315ae2d Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Sat, 11 May 2024 00:30:56 +0200 Subject: [PATCH] Get rid of strlcpy() Signed-off-by: Robert Baldyga --- modules/cas_cache/exp_obj.c | 3 ++- modules/cas_cache/layer_cache_management.c | 8 ++++---- modules/cas_cache/ocf_env.h | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/cas_cache/exp_obj.c b/modules/cas_cache/exp_obj.c index 7b2c97531..071dbba03 100644 --- a/modules/cas_cache/exp_obj.c +++ b/modules/cas_cache/exp_obj.c @@ -1,5 +1,6 @@ /* * Copyright(c) 2012-2022 Intel Corporation +* Copyright(c) 2024 Huawei Technologies * SPDX-License-Identifier: BSD-3-Clause */ #include @@ -476,7 +477,7 @@ int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name, gd->fops = &_cas_exp_obj_ops; gd->private_data = dsk; - strlcpy(gd->disk_name, exp_obj->dev_name, sizeof(gd->disk_name)); + strscpy(gd->disk_name, exp_obj->dev_name, sizeof(gd->disk_name)); cas_blk_queue_make_request(queue, _cas_exp_obj_make_rq_fn); diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index c90758841..4d09826b3 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -2122,7 +2122,7 @@ static void cache_mngt_probe_metadata_end(void *priv, int error, goto err; } - strlcpy(context->cache_name_meta, status->cache_name, + strscpy(context->cache_name_meta, status->cache_name, OCF_CACHE_NAME_SIZE); *(context->cache_mode_meta) = status->cache_mode; *(context->cache_line_size_meta) = status->cache_line_size; @@ -2487,7 +2487,7 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg, } result = 0; - strlcpy(cfg->name, cache_name_meta, OCF_CACHE_NAME_SIZE); + strscpy(cfg->name, cache_name_meta, OCF_CACHE_NAME_SIZE); cfg->cache_mode = cache_mode_meta; cfg->cache_line_size = cache_line_size_meta; default: @@ -3096,7 +3096,7 @@ int cache_mngt_get_info(struct kcas_cache_info *info) if (info->info.attached && !info->info.standby_detached) { uuid = ocf_cache_get_uuid(cache); BUG_ON(!uuid); - strlcpy(info->cache_path_name, uuid->data, + strscpy(info->cache_path_name, uuid->data, min(sizeof(info->cache_path_name), uuid->size)); } else { memset(info->cache_path_name, 0, sizeof(info->cache_path_name)); @@ -3176,7 +3176,7 @@ int cache_mngt_get_core_info(struct kcas_core_info *info) uuid = ocf_core_get_uuid(core); if (uuid->data) { - strlcpy(info->core_path_name, uuid->data, + strscpy(info->core_path_name, uuid->data, min(sizeof(info->core_path_name), uuid->size)); } diff --git a/modules/cas_cache/ocf_env.h b/modules/cas_cache/ocf_env.h index a532a3f24..ce653e0d5 100644 --- a/modules/cas_cache/ocf_env.h +++ b/modules/cas_cache/ocf_env.h @@ -1,5 +1,6 @@ /* * Copyright(c) 2012-2022 Intel Corporation +* Copyright(c) 2024 Huawei Technologies * SPDX-License-Identifier: BSD-3-Clause */ @@ -597,7 +598,7 @@ static inline int env_bit_test(int nr, const void *addr) #define env_strncmp(s1, slen1, s2, slen2) strncmp(s1, s2, \ min_t(size_t, slen1, slen2)) #define env_strncpy(dest, dmax, src, slen) ({ \ - strlcpy(dest, src, min_t(int, dmax, slen)); \ + strscpy(dest, src, min_t(int, dmax, slen)); \ 0; \ })