From b402d02197854c83609bb59de1365b1136703d8a Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sat, 5 Dec 2020 14:12:25 +0100 Subject: [PATCH 1/1] socks5_connect: Fix compiler warning from GCC9 with -D_FORTIFY_SOURCE=2 gateway.c: In function 'socks5_connect': gateway.c:1249:4: warning: 'strncpy' specified bound 295 equals destination size [-Wstringop-truncation] 1249 | strncpy(cbuf + client_pos, target_host, sizeof(cbuf) - client_pos); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The warning is harmless because 'target_host' is checked to be at most 255 bytes long. Reported by Lee. --- gateway.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway.c b/gateway.c index b341ae95..135b2173 100644 --- a/gateway.c +++ b/gateway.c @@ -1246,7 +1246,7 @@ static jb_socket socks5_connect(const struct forward_spec *fwd, cbuf[client_pos++] = (char)(hostlen & 0xffu); assert(sizeof(cbuf) - client_pos > (size_t)255); /* Using strncpy because we really want the nul byte padding. */ - strncpy(cbuf + client_pos, target_host, sizeof(cbuf) - client_pos); + strncpy(cbuf + client_pos, target_host, sizeof(cbuf) - client_pos - 1); client_pos += (hostlen & 0xffu); cbuf[client_pos++] = (char)((target_port >> 8) & 0xff); cbuf[client_pos++] = (char)((target_port ) & 0xff); -- 2.39.2