Blame SOURCES/0035-mdadm-check-value-returned-by-snprintf-against-error.patch

f9a9f5
From fd5b09c9a9107f0393ce194c4aac6e7b8f163e85 Mon Sep 17 00:00:00 2001
f9a9f5
From: Krzysztof Smolinski <krzysztof.smolinski@intel.com>
f9a9f5
Date: Fri, 16 Aug 2019 11:06:17 +0200
f9a9f5
Subject: [RHEL7.8 PATCH V2 35/47] mdadm: check value returned by snprintf
f9a9f5
 against errors
f9a9f5
f9a9f5
GCC 8 checks possible truncation during snprintf more strictly
f9a9f5
than GCC 7 which result in compilation errors. To fix this
f9a9f5
problem checking result of snprintf against errors has been added.
f9a9f5
f9a9f5
Signed-off-by: Krzysztof Smolinski <krzysztof.smolinski@intel.com>
f9a9f5
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
f9a9f5
---
f9a9f5
 sysfs.c | 12 ++++++++++--
f9a9f5
 1 file changed, 10 insertions(+), 2 deletions(-)
f9a9f5
f9a9f5
diff --git a/sysfs.c b/sysfs.c
f9a9f5
index c313781..2995713 100644
f9a9f5
--- a/sysfs.c
f9a9f5
+++ b/sysfs.c
f9a9f5
@@ -1023,12 +1023,20 @@ int sysfs_rules_apply_check(const struct mdinfo *sra,
f9a9f5
 	char dname[MAX_SYSFS_PATH_LEN];
f9a9f5
 	char resolved_path[PATH_MAX];
f9a9f5
 	char resolved_dir[PATH_MAX];
f9a9f5
+	int result;
f9a9f5
 
f9a9f5
 	if (sra == NULL || ent == NULL)
f9a9f5
 		return -1;
f9a9f5
 
f9a9f5
-	snprintf(dname, MAX_SYSFS_PATH_LEN, "/sys/block/%s/md/", sra->sys_name);
f9a9f5
-	snprintf(fname, MAX_SYSFS_PATH_LEN, "%s/%s", dname, ent->name);
f9a9f5
+	result = snprintf(dname, MAX_SYSFS_PATH_LEN,
f9a9f5
+			  "/sys/block/%s/md/", sra->sys_name);
f9a9f5
+	if (result < 0 || result >= MAX_SYSFS_PATH_LEN)
f9a9f5
+		return -1;
f9a9f5
+
f9a9f5
+	result = snprintf(fname, MAX_SYSFS_PATH_LEN,
f9a9f5
+			  "%s/%s", dname, ent->name);
f9a9f5
+	if (result < 0 || result >= MAX_SYSFS_PATH_LEN)
f9a9f5
+		return -1;
f9a9f5
 
f9a9f5
 	if (realpath(fname, resolved_path) == NULL ||
f9a9f5
 	    realpath(dname, resolved_dir) == NULL)
f9a9f5
-- 
f9a9f5
2.7.5
f9a9f5