]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
traffic-selector: Add workaround for possibly bogus warning with GCC 14
authorTobias Brunner <tobias@strongswan.org>
Fri, 25 Oct 2024 10:48:52 +0000 (12:48 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 22 Nov 2024 13:31:13 +0000 (14:31 +0100)
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

src/libstrongswan/selectors/traffic_selector.c

index fe61e3768b8763c69b0bac2f620f9b43dff55977..4022c45c1328f078bbe985f08f4992b573823dc2 100644 (file)
@@ -428,8 +428,8 @@ METHOD(traffic_selector_t, get_subset, traffic_selector_t*,
 
        /* 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;