Blame SOURCES/fcoe-utils-gcc8-fmt-truc-err.patch

30fd80
From: Chris Leech <cleech@redhat.com>
30fd80
Subject: fix build warnings/errors with GCC format-truncation checks
30fd80
30fd80
diff --git a/fcoeadm_display.c b/fcoeadm_display.c
30fd80
index 120c6084b7ca..f10cfb53d454 100644
30fd80
--- a/fcoeadm_display.c
30fd80
+++ b/fcoeadm_display.c
30fd80
@@ -254,6 +254,7 @@ static void show_full_lun_info(unsigned int hba, unsigned int port,
30fd80
 	struct dirent *dp;
30fd80
 	struct port_attributes *rport_attrs;
30fd80
 	struct port_attributes *port_attrs;
30fd80
+	int rc;
30fd80
 
30fd80
 	snprintf(path, sizeof(path),
30fd80
 		"/sys/class/scsi_device/%u:%u:%u:%u",
30fd80
@@ -287,10 +288,18 @@ static void show_full_lun_info(unsigned int hba, unsigned int port,
30fd80
 
30fd80
 		osname = dp->d_name;
30fd80
 
30fd80
-		snprintf(npath, sizeof(npath), "%s/%s/", path, osname);
30fd80
+		rc = snprintf(npath, sizeof(npath), "%s/%s/", path, osname);
30fd80
+		if (rc < 0 || rc >= sizeof(npath)) {
30fd80
+			/* error or truncation, bailing out */
30fd80
+			return;
30fd80
+		}
30fd80
 		sa_sys_read_u64(npath, "size", &lba);
30fd80
 
30fd80
-		snprintf(npath, sizeof(npath), "%s/%s/queue/", path, osname);
30fd80
+		rc = snprintf(npath, sizeof(npath), "%s/%s/queue/", path, osname);
30fd80
+		if (rc < 0 || rc >= sizeof(npath)) {
30fd80
+			/* error or truncation, bailing out */
30fd80
+			return;
30fd80
+		}
30fd80
 		sa_sys_read_u32(npath, "hw_sector_size", &blksize);
30fd80
 	}
30fd80
 
30fd80
@@ -340,6 +349,7 @@ static void show_short_lun_info(unsigned int hba, unsigned int port,
30fd80
 	char *capstr = "Unknown";
30fd80
 	char *osname = "Unknown";
30fd80
 	uint64_t size;
30fd80
+	int rc;
30fd80
 
30fd80
 	snprintf(path, sizeof(path),
30fd80
 		"/sys/class/scsi_device/%u:%u:%u:%u/device/",
30fd80
@@ -363,10 +373,18 @@ static void show_short_lun_info(unsigned int hba, unsigned int port,
30fd80
 
30fd80
 		osname = dp->d_name;
30fd80
 
30fd80
-		snprintf(npath, sizeof(npath), "%s/%s/", path, osname);
30fd80
+		rc = snprintf(npath, sizeof(npath), "%s/%s/", path, osname);
30fd80
+		if (rc < 0 || rc >= sizeof(npath)) {
30fd80
+			/* error or truncation, bailing out */
30fd80
+			return;
30fd80
+		}
30fd80
 		sa_sys_read_u64(npath, "size", &size);
30fd80
 
30fd80
-		snprintf(npath, sizeof(npath), "%s/%s/queue/", path, osname);
30fd80
+		rc = snprintf(npath, sizeof(npath), "%s/%s/queue/", path, osname);
30fd80
+		if (rc < 0 || rc >= sizeof(npath)) {
30fd80
+			/* error or truncation, bailing out */
30fd80
+			return;
30fd80
+		}
30fd80
 		sa_sys_read_u32(npath, "hw_sector_size", &blksize);
30fd80
 	}
30fd80
 
30fd80
diff --git a/fcoemon.c b/fcoemon.c
30fd80
index 9a400c56b72a..bf73a0d4c89e 100644
30fd80
--- a/fcoemon.c
30fd80
+++ b/fcoemon.c
30fd80
@@ -939,6 +939,7 @@ static struct fcoe_port *fcm_new_vlan(int ifindex, int vid, bool vn2vn)
30fd80
 		[false] = CLIF_FLAGS_FABRIC,
30fd80
 		[true] = CLIF_FLAGS_VN2VN,
30fd80
 	};
30fd80
+	int rc;
30fd80
 
30fd80
 	if (vn2vn)
30fd80
 		FCM_LOG_DBG("Auto VLAN found vn2vn on VID %d\n", vid);
30fd80
@@ -947,8 +948,15 @@ static struct fcoe_port *fcm_new_vlan(int ifindex, int vid, bool vn2vn)
30fd80
 
30fd80
 	if (rtnl_find_vlan(ifindex, vid, vlan_name)) {
30fd80
 		rtnl_get_linkname(ifindex, real_name);
30fd80
-		snprintf(vlan_name, sizeof(vlan_name), FCOE_VLAN_FORMAT,
30fd80
-			 real_name, vid);
30fd80
+		rc = snprintf(vlan_name, sizeof(vlan_name), FCOE_VLAN_FORMAT,
30fd80
+			      real_name, vid);
30fd80
+		if (rc >= sizeof(vlan_name)) {
30fd80
+			FCM_LOG("Warning: Generating FCoE VLAN device name for"
30fd80
+				"interface %s VLAN %d: format resulted in a"
30fd80
+				"name larger than IFNAMSIZ\n", real_name, vid);
30fd80
+			vlan_name[sizeof(vlan_name) - 1] = 0;
30fd80
+			FCM_LOG("\tTruncating VLAN name to %s\n", vlan_name);
30fd80
+		}
30fd80
 		vlan_create(ifindex, vid, vlan_name);
30fd80
 	}
30fd80
 	rtnl_set_iff_up(0, vlan_name);
30fd80
@@ -3549,7 +3557,7 @@ static void fcm_srv_receive(void *arg)
30fd80
 	}
30fd80
 
30fd80
 	cmd = data->cmd;
30fd80
-	strncpy(ifname, data->ifname, sizeof(data->ifname));
30fd80
+	strncpy(ifname, data->ifname, sizeof(ifname) - 1);
30fd80
 	ifname[sizeof(data->ifname)] = 0;
30fd80
 
30fd80
 	if (cmd != CLIF_PID_CMD) {
30fd80
diff --git a/libopenfcoe.c b/libopenfcoe.c
30fd80
index 07090d5a09aa..c1190adc2328 100644
30fd80
--- a/libopenfcoe.c
30fd80
+++ b/libopenfcoe.c
30fd80
@@ -179,7 +179,9 @@ static int read_fcoe_ctlr_device(struct dirent *dp, void *arg)
30fd80
 	if (!rc)
30fd80
 		goto fail;
30fd80
 
30fd80
-	sprintf(hpath, "%s/%s/", SYSFS_FCHOST, fchost);
30fd80
+	rc = snprintf(hpath, MAX_STR_LEN, "%s/%s/", SYSFS_FCHOST, fchost);
30fd80
+	if (rc < 0 || rc >= MAX_STR_LEN)
30fd80
+		goto fail;
30fd80
 
30fd80
 	rc = sa_sys_read_line(hpath, "symbolic_name", buf, sizeof(buf));
30fd80