From 5f03b994dd5de64e6b893cdc7b47211b0b7c952e Mon Sep 17 00:00:00 2001 From: Max Lv Date: Wed, 14 Oct 2026 19:42:39 +0800 Subject: [PATCH] Copy the literal ACL address without strncpy GCC 13 at -O3 rejects the strncpy from the 256-byte host into the INET6_ADDRSTRLEN buffer (-Wstringop-truncation) on glibc and UCRT64. --- src/relay/tcp.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/relay/tcp.cpp b/src/relay/tcp.cpp index a4386ebf..3250817e 100644 --- a/src/relay/tcp.cpp +++ b/src/relay/tcp.cpp @@ -713,7 +713,10 @@ Flow Connection::socks_route() noexcept known = ss_inet_ntop(direct.ss_family, raw, ip, sizeof(ip)) != nullptr; } } else { - std::strncpy(ip, target_.host, sizeof(ip) - 1); + // A literal address: it fits, but copy at most sizeof(ip) - 1 bytes. + std::size_t n = strnlen(target_.host, sizeof(ip) - 1); + std::memcpy(ip, target_.host, n); + ip[n] = '\0'; direct = target_.ip; have_direct = true; known = true;