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.
This commit is contained in:
Max Lv
2026-10-14 22:53:09 +08:00
parent 29b1983409
commit 5f03b994dd
+4 -1
View File
@@ -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;