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.
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);