When compiling with -O3 with GCC 14, we get the following warning/error:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:10: error: '__builtin_memcpy' offset [0, 3] is out of the bounds [0, 0] [-Werror=array-bounds=]
29 | return __builtin___memcpy_chk (__dest, __src, __len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30 | __glibc_objsize0 (__dest));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
Which seems completely bogus as that array has a fixed size of 16 and
some weird workarounds remove the warning (e.g. adding an assignment
to `subset->netbits` before the `memcpy()`). This is also the only
place GCC complains about and we use `memcpy()` all over the place
in this file to set those addresses.
Closes strongswan/strongswan#2509
/* we have a match in protocol, port, and address: return it... */
subset = traffic_selector_create(protocol, this->type, from_port, to_port);
- memcpy(subset->from, from, size);
- memcpy(subset->to, to, size);
+ memcpy(subset->from, from, sizeof(subset->from));
+ memcpy(subset->to, to, sizeof(subset->to));
calc_netbits(subset);
return &subset->public;