3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 17:59:25 +01:00

wiphy: fix strange compiler bug with gcc 11.2

There appears to be a compiler bug with gcc 11.2 which thinks the vht_mcs_set
is a zero length array, and the memset of size 8 is out of bounds. This is only
seen once an element is added to 'struct band'.

In file included from /usr/include/string.h:519,
                 from src/wiphy.c:34:
In function ‘memset’,
    inlined from ‘band_new_from_message’ at src/wiphy.c:1300:2,
    inlined from ‘parse_supported_bands’ at src/wiphy.c:1423:11,
    inlined from ‘wiphy_parse_attributes’ at src/wiphy.c:1596:5,
    inlined from ‘wiphy_update_from_genl’ at src/wiphy.c:1773:2:
/usr/include/bits/string_fortified.h:59:10: error: ‘__builtin_memset’ offset [0, 7] is out of the bounds [0, 0] [-Werror=array-bounds]
   59 |   return __builtin___memset_chk (__dest, __ch, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   60 |                                  __glibc_objsize0 (__dest));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
This commit is contained in:
James Prestwood 2022-07-19 15:29:50 -07:00 committed by Denis Kenzior
parent 7f63872dcf
commit a3521ff172

View File

@ -1285,7 +1285,15 @@ static struct band *band_new_from_message(struct l_genl_attr *band)
toalloc = sizeof(struct band) + count * sizeof(uint8_t); toalloc = sizeof(struct band) + count * sizeof(uint8_t);
ret = l_malloc(toalloc); ret = l_malloc(toalloc);
memset(ret, 0, toalloc); memset(ret, 0, toalloc);
#if __GNUC__ == 11 && __GNUC_MINOR__ == 2
_Pragma("GCC diagnostic push")
_Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
#endif
memset(ret->vht_mcs_set, 0xff, sizeof(ret->vht_mcs_set)); memset(ret->vht_mcs_set, 0xff, sizeof(ret->vht_mcs_set));
#if __GNUC__ == 11 && __GNUC_MINOR__ == 2
_Pragma("GCC diagnostic pop")
#endif
return ret; return ret;
} }