!46 backport Fix two gcc-11 compiler warnings

From: @liyy9 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
This commit is contained in:
openeuler-ci-bot 2025-02-28 08:57:09 +00:00 committed by Gitee
commit 602e668142
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 72 additions and 1 deletions

View File

@ -0,0 +1,67 @@
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
---
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.33.0

View File

@ -1,6 +1,6 @@
Name: fcoe-utils
Version: 1.0.33
Release: 5
Release: 6
Summary: Fibre Channel over Ethernet utilities
License: GPLv2
URL: https://github.com/morbidrsa/fcoe-utils
@ -14,6 +14,7 @@ Patch3: backport-03-use-of-uninitialized-values-detected-during-LTO.
Patch4: backport-Fix-build-error-to-change-char-type.patch
Patch5: backport-handle-NIC-names-longer-than-7-characters.patch
Patch6: bachport-Fix-GCC-12-warning.patch
Patch7: backport-Fix-two-gcc-11-compiler-warnings.patch
BuildRequires: autoconf automake libpciaccess-devel libtool lldpad-devel systemd
Requires: lldpad iproute device-mapper-multipath
@ -69,6 +70,9 @@ done
%{_mandir}/man8/*
%changelog
* Thu Dec 21 2023 liyuanyuan <liyuanyuan@xfusion.com> - 1.0.33-6
- Fix two gcc-11 compiler warnings
* Fri Dec 30 2022 xulei <xulei@xfusion.com> - 1.0.33-5
- Backport upstream patch to fix GCC 12 warning.