Skip to content

Commit

Permalink
Fix possible integer overflow calculating IPv6 address
Browse files Browse the repository at this point in the history
Found by Coverity Scan

Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Sep 8, 2024
1 parent fc63b92 commit d6e9ab6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ inet_addr_t inet_netaddr(inet_addr_t *addr, int len)
bits -= 32;
}

s6.s6_addr32[pos] = htonl(ntohl(s6.s6_addr32[pos]) & (0xffffffffu << bits));
s6.s6_addr32[pos] = htonl(ntohl(s6.s6_addr32[pos]) & ((0xffffffffU << bits) & 0xffffffffU));
sin6->sin6_addr = s6;
} else
#endif
{
struct in_addr *ina = inet_addr_get(&net);

ina->s_addr = htonl(ntohl(ina->s_addr) & (0xffffffffu << bits));
ina->s_addr = htonl(ntohl(ina->s_addr) & ((0xffffffffU << bits) & 0xffffffffU));
}

return net;
Expand Down

0 comments on commit d6e9ab6

Please sign in to comment.