From 1fd7e4513976d31509f4ad43c425f1b92e77e835 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 10 Feb 2020 10:51:49 +0100 Subject: [PATCH 1/4] Revert "platform: fix GCC warning about zero-lenght array (1)" I think this solution is not right, because "char buf" is not guaranteed to have the correct alignment. Revert, and solve it differently. This reverts commit 6345a661535bd4aaf62b2ba4bee129762abb2954. --- src/platform/nm-platform-utils.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 492572833e..b0288bdbaa 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -335,25 +335,24 @@ _ethtool_call_once (int ifindex, gpointer edata, gsize edata_size) static struct ethtool_gstrings * ethtool_get_stringset (SocketHandle *shandle, int stringset_id) { - char buf[sizeof (struct ethtool_sset_info) + sizeof (guint32)]; - struct ethtool_sset_info *sset_info; + struct { + struct ethtool_sset_info info; + guint32 sentinel; + } sset_info = { + .info.cmd = ETHTOOL_GSSET_INFO, + .info.reserved = 0, + .info.sset_mask = (1ULL << stringset_id), + }; gs_free struct ethtool_gstrings *gstrings = NULL; gsize gstrings_len; guint32 i, len; - sset_info = (struct ethtool_sset_info *) buf; - *sset_info = (struct ethtool_sset_info) { - .cmd = ETHTOOL_GSSET_INFO, - .reserved = 0, - .sset_mask = (1ULL << stringset_id), - }; - - if (_ethtool_call_handle (shandle, sset_info, sizeof (*sset_info)) < 0) + if (_ethtool_call_handle (shandle, &sset_info, sizeof (sset_info)) < 0) return NULL; - if (!sset_info->sset_mask) + if (!sset_info.info.sset_mask) return NULL; - len = sset_info->data[0]; + len = sset_info.info.data[0]; gstrings_len = sizeof (*gstrings) + (len * ETH_GSTRING_LEN); gstrings = g_malloc0 (gstrings_len); From 0931c4f2eaa2092e622dba8f58deb91760c4b53d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 10 Feb 2020 10:57:10 +0100 Subject: [PATCH 2/4] Revert "platform: fix GCC warning about zero-lenght array (2)" This reverts commit 5076fc0ca0e22b3db7987df561922d9efa840f26. --- src/platform/nm-platform-utils.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index b0288bdbaa..4f0da581d0 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -831,42 +831,41 @@ nmp_utils_ethtool_get_permanent_address (int ifindex, guint8 *buf, size_t *length) { - char ebuf[sizeof (struct ethtool_perm_addr) + NM_UTILS_HWADDR_LEN_MAX + 1]; - struct ethtool_perm_addr *edata; + struct { + struct ethtool_perm_addr e; + guint8 _extra_data[NM_UTILS_HWADDR_LEN_MAX + 1]; + } edata = { + .e.cmd = ETHTOOL_GPERMADDR, + .e.size = NM_UTILS_HWADDR_LEN_MAX, + }; guint i; g_return_val_if_fail (ifindex > 0, FALSE); - edata = (struct ethtool_perm_addr *) ebuf; - *edata = (struct ethtool_perm_addr) { - .cmd = ETHTOOL_GPERMADDR, - .size = NM_UTILS_HWADDR_LEN_MAX, - }; - - if (_ethtool_call_once (ifindex, edata, sizeof (*edata)) < 0) + if (_ethtool_call_once (ifindex, &edata, sizeof (edata)) < 0) return FALSE; - if (edata->size > NM_UTILS_HWADDR_LEN_MAX) + if (edata.e.size > NM_UTILS_HWADDR_LEN_MAX) return FALSE; - if (edata->size < 1) + if (edata.e.size < 1) return FALSE; - if (NM_IN_SET (edata->data[0], 0, 0xFF)) { + if (NM_IN_SET (edata.e.data[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->size; i++) { - if (edata->data[0] != edata->data[i]) + for (i = 1; i < edata.e.size; i++) { + if (edata.e.data[0] != edata.e.data[i]) goto not_all_0or1; } return FALSE; } not_all_0or1: - memcpy (buf, edata->data, edata->size); - *length = edata->size; + memcpy (buf, edata.e.data, edata.e.size); + *length = edata.e.size; return TRUE; } From 16e1e44c5ef96d28663208b005cc3343b95ba634 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 10 Feb 2020 10:55:12 +0100 Subject: [PATCH 3/4] platform: fix GCC warning about zero-length array in ethtool_get_stringset() 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 ‘ethtool_get_stringset’: src/platform/nm-platform-utils.c:355:27: error: array subscript 0 is outside the bounds of an interior zero-length array ‘__u32[0]’ {aka ‘unsigned int[0]’} [-Werror=zero-length-bounds] 355 | len = sset_info.info.data[0]; | ~~~~~~~~~~~~~~~~~~~^~~ In file included from src/platform/nm-platform-utils.c:12: /usr/include/linux/ethtool.h:647:8: note: while referencing ‘data’ 647 | __u32 data[0]; | ^~~~ Fix this warning. --- src/platform/nm-platform-utils.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 4f0da581d0..39bf719bae 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -343,6 +343,7 @@ ethtool_get_stringset (SocketHandle *shandle, int stringset_id) .info.reserved = 0, .info.sset_mask = (1ULL << stringset_id), }; + const guint32 *pdata; gs_free struct ethtool_gstrings *gstrings = NULL; gsize gstrings_len; guint32 i, len; @@ -352,7 +353,9 @@ ethtool_get_stringset (SocketHandle *shandle, int stringset_id) if (!sset_info.info.sset_mask) return NULL; - len = sset_info.info.data[0]; + pdata = (guint32 *) sset_info.info.data; + + len = *pdata; gstrings_len = sizeof (*gstrings) + (len * ETH_GSTRING_LEN); gstrings = g_malloc0 (gstrings_len); From d892a35395c37a94219c3e00202f190de8d5b991 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 10 Feb 2020 11:01:43 +0100 Subject: [PATCH 4/4] 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. --- 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 39bf719bae..9529b9c5f0 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -841,6 +841,7 @@ nmp_utils_ethtool_get_permanent_address (int ifindex, .e.cmd = ETHTOOL_GPERMADDR, .e.size = NM_UTILS_HWADDR_LEN_MAX, }; + const guint8 *pdata; guint i; @@ -854,20 +855,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; }