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