Blob Blame History Raw
From ebad3af29b401dec7203e8fa5a77bcf16532f49c Mon Sep 17 00:00:00 2001
From: Jes Sorensen <jsorensen@fb.com>
Date: Wed, 30 May 2018 12:10:13 -0400
Subject: [RHEL7.5 PATCH 15/26] super-intel: Do not truncate last character of
 volume name

Clear up strncpy abuse to avoid gcc-8.1 complaining about truncating
the string.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
---
 super-intel.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/super-intel.c b/super-intel.c
index 520d292..aa93a9e 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -7587,11 +7587,12 @@ static int update_subarray_imsm(struct supertype *st, char *subarray,
 			append_metadata_update(st, u, sizeof(*u));
 		} else {
 			struct imsm_dev *dev;
-			int i;
+			int i, namelen;
 
 			dev = get_imsm_dev(super, vol);
-			strncpy((char *) dev->volume, name, MAX_RAID_SERIAL_LEN);
-			dev->volume[MAX_RAID_SERIAL_LEN-1] = '\0';
+			memset(dev->volume, '\0', MAX_RAID_SERIAL_LEN);
+			namelen = min((int)strlen(name), MAX_RAID_SERIAL_LEN);
+			memcpy(dev->volume, name, namelen);
 			for (i = 0; i < mpb->num_raid_devs; i++) {
 				dev = get_imsm_dev(super, i);
 				handle_missing(super, dev);
-- 
2.7.4