dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/Replace-snprintf-with-strncpy-at-some-places-to-avoi.patch

b7f731
From 618f4e6d63c8c09d8d4002770e44617f3477f137 Mon Sep 17 00:00:00 2001
b7f731
From: Xiao Ni <xni@redhat.com>
b7f731
Date: Sat, 18 Mar 2017 10:33:44 +0800
b7f731
Subject: [RHEL7.5 PATCH 015/169] Replace snprintf with strncpy at some
b7f731
 places to avoid truncation
b7f731
b7f731
In gcc7 there are some building errors like:
b7f731
directive output may be truncated writing up to 31 bytes into a region of size 24
b7f731
snprintf(str, MPB_SIG_LEN, %s, mpb->sig);
b7f731
b7f731
It just need to copy one string to target. So use strncpy to replace it.
b7f731
b7f731
For this line code: snprintf(str, MPB_SIG_LEN, %s, mpb->sig);
b7f731
Because mpb->sig has the content of version after magic, so
b7f731
it's better to use strncpy to replace snprintf too.
b7f731
b7f731
Signed-off-by: Xiao Ni <xni@redhat.com>
b7f731
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
b7f731
---
b7f731
 super-intel.c | 9 ++++++---
b7f731
 1 file changed, 6 insertions(+), 3 deletions(-)
b7f731
b7f731
diff --git a/super-intel.c b/super-intel.c
b7f731
index d5e9517..343f20d 100644
b7f731
--- a/super-intel.c
b7f731
+++ b/super-intel.c
b7f731
@@ -1811,7 +1811,8 @@ static void examine_super_imsm(struct supertype *st, char *homehost)
b7f731
 	__u32 reserved = imsm_reserved_sectors(super, super->disks);
b7f731
 	struct dl *dl;
b7f731
 
b7f731
-	snprintf(str, MPB_SIG_LEN, "%s", mpb->sig);
b7f731
+	strncpy(str, (char *)mpb->sig, MPB_SIG_LEN);
b7f731
+	str[MPB_SIG_LEN-1] = '\0';
b7f731
 	printf("          Magic : %s\n", str);
b7f731
 	snprintf(str, strlen(MPB_VERSION_RAID0), "%s", get_imsm_version(mpb));
b7f731
 	printf("        Version : %s\n", get_imsm_version(mpb));
b7f731
@@ -7142,14 +7143,16 @@ static int update_subarray_imsm(struct supertype *st, char *subarray,
b7f731
 
b7f731
 			u->type = update_rename_array;
b7f731
 			u->dev_idx = vol;
b7f731
-			snprintf((char *) u->name, MAX_RAID_SERIAL_LEN, "%s", name);
b7f731
+			strncpy((char *) u->name, name, MAX_RAID_SERIAL_LEN);
b7f731
+			u->name[MAX_RAID_SERIAL_LEN-1] = '\0';
b7f731
 			append_metadata_update(st, u, sizeof(*u));
b7f731
 		} else {
b7f731
 			struct imsm_dev *dev;
b7f731
 			int i;
b7f731
 
b7f731
 			dev = get_imsm_dev(super, vol);
b7f731
-			snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, "%s", name);
b7f731
+			strncpy((char *) dev->volume, name, MAX_RAID_SERIAL_LEN);
b7f731
+			dev->volume[MAX_RAID_SERIAL_LEN-1] = '\0';
b7f731
 			for (i = 0; i < mpb->num_raid_devs; i++) {
b7f731
 				dev = get_imsm_dev(super, i);
b7f731
 				handle_missing(super, dev);
b7f731
-- 
b7f731
2.7.4
b7f731