From 4761753a6f62a379d4b111621049ab180c7b9afc Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sat, 4 May 2024 21:56:34 +0200 Subject: [PATCH] cov: replace strcpy with memcpy --- device_mapper/libdm-common.c | 11 +++++++---- libdm/libdm-common.c | 11 +++++++---- libdm/mm/dbg_malloc.c | 6 ++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/device_mapper/libdm-common.c b/device_mapper/libdm-common.c index ce55d210c..d93fce1f9 100644 --- a/device_mapper/libdm-common.c +++ b/device_mapper/libdm-common.c @@ -1451,9 +1451,10 @@ struct node_op_parms { static void _store_str(char **pos, char **ptr, const char *str) { - strcpy(*pos, str); + size_t len = strlen(str); + memcpy(*pos, str, len + 1); *ptr = *pos; - *pos += strlen(*ptr) + 1; + *pos += len; } static void _del_node_op(struct node_op_parms *nop) @@ -1703,15 +1704,17 @@ const char *dm_sysfs_dir(void) */ int dm_set_uuid_prefix(const char *uuid_prefix) { + size_t len; + if (!uuid_prefix) return_0; - if (strlen(uuid_prefix) > DM_MAX_UUID_PREFIX_LEN) { + if ((len = strlen(uuid_prefix)) > DM_MAX_UUID_PREFIX_LEN) { log_error("New uuid prefix %s too long.", uuid_prefix); return 0; } - strcpy(_default_uuid_prefix, uuid_prefix); + memcpy(_default_uuid_prefix, uuid_prefix, len + 1); return 1; } diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c index b7c8d5d4d..fb8b72aa4 100644 --- a/libdm/libdm-common.c +++ b/libdm/libdm-common.c @@ -1449,9 +1449,10 @@ struct node_op_parms { static void _store_str(char **pos, char **ptr, const char *str) { - strcpy(*pos, str); + size_t len = strlen(str); + memcpy(*pos, str, len + 1); *ptr = *pos; - *pos += strlen(*ptr) + 1; + *pos += len; } static void _del_node_op(struct node_op_parms *nop) @@ -1701,15 +1702,17 @@ const char *dm_sysfs_dir(void) */ int dm_set_uuid_prefix(const char *uuid_prefix) { + size_t len; + if (!uuid_prefix) return_0; - if (strlen(uuid_prefix) > DM_MAX_UUID_PREFIX_LEN) { + if ((len = strlen(uuid_prefix)) > DM_MAX_UUID_PREFIX_LEN) { log_error("New uuid prefix %s too long.", uuid_prefix); return 0; } - strcpy(_default_uuid_prefix, uuid_prefix); + memcpy(_default_uuid_prefix, uuid_prefix, len + 1); return 1; } diff --git a/libdm/mm/dbg_malloc.c b/libdm/mm/dbg_malloc.c index d8799d78d..a2be12e45 100644 --- a/libdm/mm/dbg_malloc.c +++ b/libdm/mm/dbg_malloc.c @@ -42,14 +42,16 @@ void dm_bounds_check_debug(void); char *dm_strdup_aux(const char *str, const char *file, int line) { char *ret; + size_t len; if (!str) { log_error(INTERNAL_ERROR "dm_strdup called with NULL pointer"); return NULL; } - if ((ret = dm_malloc_aux_debug(strlen(str) + 1, file, line))) - strcpy(ret, str); + len = strlen(str) + 1; + if ((ret = dm_malloc_aux_debug(len, file, line))) + memcpy(ret, str, len); return ret; }