[Buildroot] [PATCH 1/1] package/boost: fix asio.hpp compile errors with gcc >= 15

Adam Duskett <[email protected]>
Newsgroups net.busybox.buildroot
Message-ID <[email protected]>
This commit unintentionally fixed a compile error when programs
include the asio.hpp header with gcc versions >= 15.

```
In function ‘void* memcpy(void*, const void*, size_t)’,

inlined from ‘static boost::asio::ip::basic_resolver_results<InternetProtocol>
    boost::asio::ip::basic_resolver_results<InternetProtocol>::create(boost::asio::detail::addrinfo_type*,
    const std::string&, const std::string&) [with InternetProtocol = boost::asio::ip::tcp]’
    at /usr/include/boost/asio/ip/basic_resolver_results.hpp:147:15:

/usr/include/bits/string_fortified.h:29:33:
    error: ‘void* __builtin___memcpy_chk(void*, const void*, unsigned int, unsigned int)’
    forming offset [28, 128] is out of the bounds [0, 28] of object ‘endpoint’ with type
    ‘boost::asio::ip::tcp::endpoint’ {aka ‘boost::asio::ip::basic_endpoint<boost::asio::ip::tcp>’}
    [-Werror=array-bounds=]
```

Backport URL: https://github.com/boostorg/asio/commit/b2478a9ba9ed76d7c858419e3f677cc454591d45

Fixes: None reported
Signed-off-by: Adam Duskett <[email protected]>
---
 ...002-remove-FORTIFY_SOURCE-workaround.patch | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 package/boost/0002-remove-FORTIFY_SOURCE-workaround.patch

diff --git a/package/boost/0002-remove-FORTIFY_SOURCE-workaround.patch b/package/boost/0002-remove-FORTIFY_SOURCE-workaround.patch
new file mode 100644
index 0000000000..d044b62676
--- /dev/null
+++ b/package/boost/0002-remove-FORTIFY_SOURCE-workaround.patch
@@ -0,0 +1,75 @@
+From b3d87da5f87e2907ed004edf1c72ad3942ff1165 Mon Sep 17 00:00:00 2001
+From: Christopher Kohlhoff <[email protected]>
+Date: Wed, 5 Aug 2026 16:07:19 +0200
+Subject: [PATCH] Remove _FORTIFY_SOURCE workaround.
+
+This commit unintentionally fixed a compile error when programs
+include the asio.hpp header with gcc versions >= 15.
+
+```
+In function ‘void* memcpy(void*, const void*, size_t)’,
+
+inlined from ‘static boost::asio::ip::basic_resolver_results<InternetProtocol>
+    boost::asio::ip::basic_resolver_results<InternetProtocol>::create(boost::asio::detail::addrinfo_type*,
+    const std::string&, const std::string&) [with InternetProtocol = boost::asio::ip::tcp]’
+    at /usr/include/boost/asio/ip/basic_resolver_results.hpp:147:15:
+
+/usr/include/bits/string_fortified.h:29:33:
+    error: ‘void* __builtin___memcpy_chk(void*, const void*, unsigned int, unsigned int)’
+    forming offset [28, 128] is out of the bounds [0, 28] of object ‘endpoint’ with type
+    ‘boost::asio::ip::tcp::endpoint’ {aka ‘boost::asio::ip::basic_endpoint<boost::asio::ip::tcp>’}
+    [-Werror=array-bounds=]
+```
+
+
+Original patch commit message:
+```
+The previous workaround for _FORTIFY_SOURCE warnings increased the size
+of all IP endpoint objects. Instead, try fixing the warning at the point
+where it occurs, by limiting the length memcpy-ed while processing the
+addrinfo results from getaddrinfo.
+```
+
+Upstream: Backport [https://github.com/boostorg/asio/commit/b2478a9ba9ed76d7c858419e3f677cc454591d45]
+Signed-off-by: Adam Duskett <[email protected]>
+Signed-off-by: Christopher Kohlhoff <[email protected]>
+---
+ boost/asio/ip/basic_resolver_results.hpp | 22 ++++++++++++++--------
+ 1 file changed, 14 insertions(+), 8 deletions(-)
+
+diff --git a/boost/asio/ip/basic_resolver_results.hpp b/boost/asio/ip/basic_resolver_results.hpp
+index 0127473e2..87fa3fadf 100644
+--- a/boost/asio/ip/basic_resolver_results.hpp
++++ b/boost/asio/ip/basic_resolver_results.hpp
+@@ -141,14 +141,20 @@ public:
+       if (address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET)
+           || address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET6))
+       {
+-        using namespace std; // For memcpy.
+-        typename InternetProtocol::endpoint endpoint;
+-        endpoint.resize(static_cast<std::size_t>(address_info->ai_addrlen));
+-        memcpy(endpoint.data(), address_info->ai_addr,
+-            address_info->ai_addrlen);
+-        results.values_->push_back(
+-            basic_resolver_entry<InternetProtocol>(endpoint,
+-              actual_host_name, service_name));
++        const std::size_t expected_size =
++          address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET)
++            ? sizeof(boost::asio::detail::sockaddr_in4_type)
++            : sizeof(boost::asio::detail::sockaddr_in6_type);
++        if (address_info->ai_addrlen >= expected_size)
++        {
++          using namespace std; // For memcpy.
++          typename InternetProtocol::endpoint endpoint;
++          endpoint.resize(expected_size);
++          memcpy(endpoint.data(), address_info->ai_addr, expected_size);
++          results.values_->push_back(
++              basic_resolver_entry<InternetProtocol>(endpoint,
++                actual_host_name, service_name));
++        }
+       }
+       address_info = address_info->ai_next;
+     }
+-- 
+2.55.0
+
-- 
2.55.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.