mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-29 04:03:45 +00:00
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:
+4
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user