[lvm-devel] stable-2.02 - gcc: avoid stack alloc arithmetic

Zdenek Kabelac zkabelac at sourceware.org
Fri Oct 16 19:10:47 UTC 2020


Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d48266b7fba54f7d57f233f51e9f084fbff69956
Commit:        d48266b7fba54f7d57f233f51e9f084fbff69956
Parent:        90a9a7785e7ad82f6878bb0520989b5b3df00f22
Author:        Zdenek Kabelac <zkabelac at redhat.com>
AuthorDate:    Fri Aug 28 18:46:06 2020 +0200
Committer:     Zdenek Kabelac <zkabelac at redhat.com>
CommitterDate: Fri Oct 16 16:02:05 2020 +0200

gcc: avoid stack alloc arithmetic

---
 tools/lvconvert.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index fc740fb3e..014163f49 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1173,6 +1173,8 @@ static int _lvconvert_validate_thin(struct logical_volume *lv,
 static int _raid_split_image_conversion(struct logical_volume *lv)
 {
 	const char *s;
+	char raidlv_name[NAME_LEN];
+	const struct logical_volume *tmp_lv;
 
 	if (lv_is_raid_with_tracking(lv)) {
 		log_error("Conversion of tracking raid1 LV %s is not supported.",
@@ -1182,12 +1184,7 @@ static int _raid_split_image_conversion(struct logical_volume *lv)
 
 	if (lv_is_raid_image(lv) &&
 	    (s = strstr(lv->name, "_rimage_"))) {
-		size_t len = s - lv->name;
-		char raidlv_name[len + 1];
-		const struct logical_volume *tmp_lv;
-
-		strncpy(raidlv_name, lv->name, len);
-		raidlv_name[len] = '\0';
+		(void) dm_strncpy(raidlv_name, lv->name, s - lv->name);
 
 		if (!(tmp_lv = find_lv(lv->vg, raidlv_name))) {
 			log_error(INTERNAL_ERROR "Failed to find RaidLV of RAID subvolume %s.",




More information about the lvm-devel mailing list