fcoe-utils/0001-Fix-two-gcc-11-compiler-warnings.patch

70 lines
2.3 KiB
Diff
Raw Normal View History

From 66616e988778c45a316d6b286fda732843f25297 Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Mon, 22 Mar 2021 18:28:33 -0700
Subject: [PATCH] Fix two gcc-11 compiler warnings.
Gcc-11 is aggressive about gaurding against array copies. So be
clear about what we want to copy, and where we are copying it.
Changes from V1:
* simplified both cases based on review comments
* no need to copy the data twice
reference: https://github.com/morbidrsa/fcoe-utils/commit/66616e988778c45a316d6b286fda732843f25297
---
fcping.c | 8 ++++++--
fipvlan.c | 11 +++++++++--
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/fcping.c b/fcping.c
index bf2bc0f0c78..21830a52524 100644
--- a/fcping.c
+++ b/fcping.c
@@ -570,6 +570,7 @@ fp_ns_get_id(uint32_t op, fc_wwn_t wwn, char *response, size_t *resp_len)
struct sg_io_v4 sg_io;
size_t actual_len;
int cmd, rc = 0;
+ uint32_t *uct = (uint32_t *)&ct.hdr;
memset((char *)&cdb, 0, sizeof(cdb));
memset(&ct, 0, sizeof(ct));
@@ -584,8 +585,11 @@ fp_ns_get_id(uint32_t op, fc_wwn_t wwn, char *response, size_t *resp_len)
cdb.msgcode = FC_BSG_HST_CT;
hton24(cdb.rqst_data.h_ct.port_id, 0xfffffc);
- memcpy(&cdb.rqst_data.h_ct.preamble_word0, &ct.hdr,
- 3 * sizeof(uint32_t));
+
+ /* copy preamble words one at a time, to make compiler happy */
+ cdb.rqst_data.h_ct.preamble_word0 = uct[0];
+ cdb.rqst_data.h_ct.preamble_word1 = uct[1];
+ cdb.rqst_data.h_ct.preamble_word2 = uct[2];
sg_io.guard = 'Q';
sg_io.protocol = BSG_PROTOCOL_SCSI;
diff --git a/fipvlan.c b/fipvlan.c
index c8a07339314..4433c0abf76 100644
--- a/fipvlan.c
+++ b/fipvlan.c
@@ -447,8 +447,15 @@ static void rtnl_recv_newlink(struct nlmsghdr *nh)
iff->iflink = *(int *)RTA_DATA(ifla[IFLA_LINK]);
else
iff->iflink = iff->ifindex;
- memcpy(iff->mac_addr, RTA_DATA(ifla[IFLA_ADDRESS]), ETHER_ADDR_LEN);
- strncpy(iff->ifname, RTA_DATA(ifla[IFLA_IFNAME]), IFNAMSIZ);
+
+ /*
+ * copy MAC address and interface name using intermediate
+ * arrays, so gcc-11 knows we are not overflowing buffers
+ */
+ if (ifla[IFLA_ADDRESS])
+ memcpy(iff->mac_addr, RTA_DATA(ifla[IFLA_ADDRESS]), ETHER_ADDR_LEN);
+ if (ifla[IFLA_IFNAME])
+ memcpy(iff->ifname, RTA_DATA(ifla[IFLA_IFNAME]), IFNAMSIZ);
iff->ifname[IFNAMSIZ - 1] = '\0';
if (ifla[IFLA_LINKINFO]) {
--
2.39.1