From eb3f64cbd71f2895830e50b9ae9ed3e355a76afd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 10 Feb 2020 11:01:43 +0100 Subject: [PATCH] platform: fix GCC warning about zero-length array in nmp_utils_ethtool_get_permanent_address() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 10 complains about accesses to elements of zero-length arrays that overlap other members of the same object: src/platform/nm-platform-utils.c: In function ‘nmp_utils_ethtool_get_permanent_address’: src/platform/nm-platform-utils.c:854:29: error: array subscript 0 is outside the bounds of an interior zero-length array ‘__u8[0]’ {aka ‘unsigned char[0]’} [-Werror=zero-length-bounds] 854 | if (NM_IN_SET (edata.e.data[0], 0, 0xFF)) { ./shared/nm-glib-aux/nm-macros-internal.h:731:20: note: in definition of macro ‘_NM_IN_SET_EVAL_N’ Fix this warning. (cherry picked from commit d892a35395c37a94219c3e00202f190de8d5b991) (cherry picked from commit c1417087c81267c9a34da5770876ada512126592) (cherry picked from commit f7b9d063067b6928abe9294f876de1f270190de9) --- src/platform/nm-platform-utils.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index f925bbbec0..b17bae90a4 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -705,6 +705,7 @@ nmp_utils_ethtool_get_permanent_address (int ifindex, struct ethtool_perm_addr e; guint8 _extra_data[NM_UTILS_HWADDR_LEN_MAX + 1]; } edata; + const guint8 *pdata; guint i; g_return_val_if_fail (ifindex > 0, FALSE); @@ -721,20 +722,22 @@ nmp_utils_ethtool_get_permanent_address (int ifindex, if (edata.e.size < 1) return FALSE; - if (NM_IN_SET (edata.e.data[0], 0, 0xFF)) { + pdata = (const guint8 *) edata.e.data; + + if (NM_IN_SET (pdata[0], 0, 0xFF)) { /* Some drivers might return a permanent address of all zeros. * Reject that (rh#1264024) * * Some drivers return a permanent address of all ones. Reject that too */ for (i = 1; i < edata.e.size; i++) { - if (edata.e.data[0] != edata.e.data[i]) + if (pdata[0] != pdata[i]) goto not_all_0or1; } return FALSE; } not_all_0or1: - memcpy (buf, edata.e.data, edata.e.size); + memcpy (buf, pdata, edata.e.size); *length = edata.e.size; return TRUE; }