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.
This commit is contained in:
emile-ross 2026-06-22 03:09:12 -04:00
parent 806c0af5ee
commit d3438e7bff
No known key found for this signature in database
GPG key ID: 555961FA8FFF0E01

View file

@ -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 ... */