From d3438e7bffdf12f53a28dff33acf19035a2b0dcf Mon Sep 17 00:00:00 2001 From: emile-ross Date: Mon, 22 Jun 2026 03:09:12 -0400 Subject: [PATCH] Fix signedness & buffer handling warnings in tcpip.cc Replace strncpy() with inet_ntop() to prevent potential truncation Cast tcplen to size_t to resolve signedness comparison warning. Changes: - Use ``inet_ntop(AF_INET, &bullshit, sourcehost, sizeof(sourcehost))`` instead of ``strncpy(sourcehost, inet_ntoa(bullshit), 16)`` to ensure string termination - Cast tcplen to size_t in assert ```c assert((size_t)tcplen >= sizeof(tcp)) ``` to remove the -Wsign-compare warning This removes compiler warnings and improves code safety. --- tcpip.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tcpip.cc b/tcpip.cc index 1fcdb1a3b..180be6aef 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -1119,7 +1119,7 @@ int readtcppacket(const u8 *packet, int readdata) { bullshit2.s_addr = ip->ip_dst.s_addr; realfrag = htons(ntohs(ip->ip_off) & IP_OFFMASK); tot_len = htons(ip->ip_len); - strncpy(sourcehost, inet_ntoa(bullshit), 16); + inet_ntop(AF_INET, &bullshit, sourcehost, sizeof(sourcehost)); i = 4 * (ntohs(ip->ip_hl) + ntohs(tcp->th_off)); if (ip->ip_p == IPPROTO_TCP) { if (realfrag) @@ -1642,7 +1642,7 @@ int gettcpopt_ts(const u8 *tcppkt, int tcplen, u32 *timestamp, u32 *echots) { int op; int oplen; struct tcp_hdr tcp; - assert(tcplen >= sizeof(tcp)); + assert((size_t)tcplen >= sizeof(tcp)); memcpy(&tcp, tcppkt, sizeof(tcp)); /* first we find where the tcp options start ... */