mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 09:38:06 +02:00
platform: fix GCC warning about zero-length array in nmp_utils_ethtool_get_permanent_address()
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 d892a35395)
(cherry picked from commit c1417087c8)
(cherry picked from commit f7b9d06306)
This commit is contained in:
parent
2ebb933596
commit
eb3f64cbd7
1 changed files with 6 additions and 3 deletions
|
|
@ -705,6 +705,7 @@ nmp_utils_ethtool_get_permanent_address (int ifindex,
|
||||||
struct ethtool_perm_addr e;
|
struct ethtool_perm_addr e;
|
||||||
guint8 _extra_data[NM_UTILS_HWADDR_LEN_MAX + 1];
|
guint8 _extra_data[NM_UTILS_HWADDR_LEN_MAX + 1];
|
||||||
} edata;
|
} edata;
|
||||||
|
const guint8 *pdata;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
g_return_val_if_fail (ifindex > 0, FALSE);
|
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)
|
if (edata.e.size < 1)
|
||||||
return FALSE;
|
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.
|
/* Some drivers might return a permanent address of all zeros.
|
||||||
* Reject that (rh#1264024)
|
* Reject that (rh#1264024)
|
||||||
*
|
*
|
||||||
* Some drivers return a permanent address of all ones. Reject that too */
|
* Some drivers return a permanent address of all ones. Reject that too */
|
||||||
for (i = 1; i < edata.e.size; i++) {
|
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;
|
goto not_all_0or1;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
not_all_0or1:
|
not_all_0or1:
|
||||||
memcpy (buf, edata.e.data, edata.e.size);
|
memcpy (buf, pdata, edata.e.size);
|
||||||
*length = edata.e.size;
|
*length = edata.e.size;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue