From e7a54c1a50282e2f3d08fafc87d2fe5e163066f0 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Tue, 9 Apr 2024 11:36:31 +0200 Subject: [PATCH] cov: use safer version with size limitation Although there is likely not much risk of having chance of overwritting given buffers use safer variant. Use dm_strncpy() when just copying %s. --- device_mapper/libdm-string.c | 4 ++-- libdm/libdm-string.c | 4 ++-- tools/lvchange.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/device_mapper/libdm-string.c b/device_mapper/libdm-string.c index 85f1ff403..fc38d9f26 100644 --- a/device_mapper/libdm-string.c +++ b/device_mapper/libdm-string.c @@ -385,7 +385,7 @@ char *dm_build_dm_uuid(struct dm_pool *mem, const char *uuid_prefix, const char return NULL; } - sprintf(dmuuid, "%s%s%s%s", uuid_prefix, lvid, (*layer) ? "-" : "", layer); + snprintf(dmuuid, len, "%s%s%s%s", uuid_prefix, lvid, (*layer) ? "-" : "", layer); return dmuuid; } @@ -552,7 +552,7 @@ const char *dm_size_to_string(struct dm_pool *mem, uint64_t size, if (size == UINT64_C(0)) { if (base == BASE_UNKNOWN) s = 0; - sprintf(size_buf, "0%s", include_suffix ? size_str[base + s][suffix_type] : ""); + snprintf(size_buf, SIZE_BUF, "0%s", include_suffix ? size_str[base + s][suffix_type] : ""); return size_buf; } diff --git a/libdm/libdm-string.c b/libdm/libdm-string.c index a445dcb92..391a4786e 100644 --- a/libdm/libdm-string.c +++ b/libdm/libdm-string.c @@ -385,7 +385,7 @@ char *dm_build_dm_uuid(struct dm_pool *mem, const char *uuid_prefix, const char return NULL; } - sprintf(dmuuid, "%s%s%s%s", uuid_prefix, lvid, (*layer) ? "-" : "", layer); + snprintf(dmuuid, len, "%s%s%s%s", uuid_prefix, lvid, (*layer) ? "-" : "", layer); return dmuuid; } @@ -552,7 +552,7 @@ const char *dm_size_to_string(struct dm_pool *mem, uint64_t size, if (size == UINT64_C(0)) { if (base == BASE_UNKNOWN) s = 0; - sprintf(size_buf, "0%s", include_suffix ? size_str[base + s][suffix_type] : ""); + snprintf(size_buf, SIZE_BUF, "0%s", include_suffix ? size_str[base + s][suffix_type] : ""); return size_buf; } diff --git a/tools/lvchange.c b/tools/lvchange.c index 520880a02..a6f071a91 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -938,9 +938,9 @@ static int _lvchange_writemostly(struct logical_volume *lv, if ((tmp_str_len < 3) || (tmp_str[tmp_str_len - 2] != ':')) /* Default to 'y' if no mode specified */ - sprintf(pv_names[i], "%s:y", tmp_str); + snprintf(pv_names[i], tmp_str_len + 3, "%s:y", tmp_str); else - sprintf(pv_names[i], "%s", tmp_str); + dm_strncpy(pv_names[i], tmp_str, tmp_str_len + 3); i++; }