mirror of
https://github.com/nmap/nmap.git
synced 2026-07-10 18:24:41 +00:00
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:
parent
806c0af5ee
commit
d3438e7bff
1 changed files with 2 additions and 2 deletions
4
tcpip.cc
4
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 ... */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue