mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-04 00:30:17 +01:00
platform: fix GCC warning about zero-lenght array (2)
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.
This commit is contained in:
parent
6345a66153
commit
5076fc0ca0
1 changed files with 16 additions and 15 deletions
|
|
@ -832,41 +832,42 @@ nmp_utils_ethtool_get_permanent_address (int ifindex,
|
|||
guint8 *buf,
|
||||
size_t *length)
|
||||
{
|
||||
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,
|
||||
};
|
||||
char ebuf[sizeof (struct ethtool_perm_addr) + NM_UTILS_HWADDR_LEN_MAX + 1];
|
||||
struct ethtool_perm_addr *edata;
|
||||
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (ifindex > 0, FALSE);
|
||||
|
||||
if (_ethtool_call_once (ifindex, &edata, sizeof (edata)) < 0)
|
||||
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)
|
||||
return FALSE;
|
||||
|
||||
if (edata.e.size > NM_UTILS_HWADDR_LEN_MAX)
|
||||
if (edata->size > NM_UTILS_HWADDR_LEN_MAX)
|
||||
return FALSE;
|
||||
if (edata.e.size < 1)
|
||||
if (edata->size < 1)
|
||||
return FALSE;
|
||||
|
||||
if (NM_IN_SET (edata.e.data[0], 0, 0xFF)) {
|
||||
if (NM_IN_SET (edata->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.e.size; i++) {
|
||||
if (edata.e.data[0] != edata.e.data[i])
|
||||
for (i = 1; i < edata->size; i++) {
|
||||
if (edata->data[0] != edata->data[i])
|
||||
goto not_all_0or1;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
not_all_0or1:
|
||||
memcpy (buf, edata.e.data, edata.e.size);
|
||||
*length = edata.e.size;
|
||||
memcpy (buf, edata->data, edata->size);
|
||||
*length = edata->size;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue