mirror of
https://github.com/nmap/nmap.git
synced 2026-08-27 11:55:27 +00:00
Address code review: guard sockaddr_in6 with HAVE_IPV6
Replace the ternary operator with an if/else-if chain and wrap the AF_INET6 case in #if HAVE_IPV6 to match existing nmap style and avoid compilation failures on non-IPv6 builds. Unknown address families now fall through without modifying the length, which is the safe behaviour. Suggested by Copilot review of PR #3439.
This commit is contained in:
parent
9e88dd2da2
commit
d0fa89658c
3 changed files with 24 additions and 8 deletions
16
nse_nsock.cc
16
nse_nsock.cc
|
|
@ -427,8 +427,12 @@ static nse_nsock_udata *check_nsock_udata (lua_State *L, int idx, bool open)
|
|||
} else if (0 == o.SourceSockAddr(&ss, &sslen)) {
|
||||
// Use the exact protocol-specific length. Some platforms (e.g. FreeBSD)
|
||||
// reject sizeof(sockaddr_storage) passed to bind() with EINVAL.
|
||||
sslen = (ss.ss_family == AF_INET6) ?
|
||||
sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
|
||||
if (ss.ss_family == AF_INET)
|
||||
sslen = sizeof(struct sockaddr_in);
|
||||
#if HAVE_IPV6
|
||||
else if (ss.ss_family == AF_INET6)
|
||||
sslen = sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
nsock_iod_set_localaddr(nu->nsiod, &ss, sslen);
|
||||
}
|
||||
if (o.ipoptionslen)
|
||||
|
|
@ -554,8 +558,12 @@ static int connect (lua_State *L, int status, lua_KContext ctx)
|
|||
} else if (0 == o.SourceSockAddr(&ss, &sslen)) {
|
||||
// Use the exact protocol-specific length. Some platforms (e.g. FreeBSD)
|
||||
// reject sizeof(sockaddr_storage) passed to bind() with EINVAL.
|
||||
sslen = (ss.ss_family == AF_INET6) ?
|
||||
sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
|
||||
if (ss.ss_family == AF_INET)
|
||||
sslen = sizeof(struct sockaddr_in);
|
||||
#if HAVE_IPV6
|
||||
else if (ss.ss_family == AF_INET6)
|
||||
sslen = sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
nsock_iod_set_localaddr(nu->nsiod, &ss, sslen);
|
||||
}
|
||||
if (o.ipoptionslen)
|
||||
|
|
|
|||
|
|
@ -436,8 +436,12 @@ static void init_socket(int sd, const HostScanStats *hss, UltraScanInfo *USI) {
|
|||
if (!bind_failed && 0 == o.SourceSockAddr(&ss, &sslen)) {
|
||||
// Use the exact protocol-specific length. Some platforms (e.g. FreeBSD)
|
||||
// reject sizeof(sockaddr_storage) passed to bind() with EINVAL.
|
||||
sslen = (ss.ss_family == AF_INET6) ?
|
||||
sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
|
||||
if (ss.ss_family == AF_INET)
|
||||
sslen = sizeof(struct sockaddr_in);
|
||||
#if HAVE_IPV6
|
||||
else if (ss.ss_family == AF_INET6)
|
||||
sslen = sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
if (::bind(sd, (struct sockaddr*)&ss, sslen) != 0) {
|
||||
error("%s: Problem binding source address (%s), errno: %d", __func__, inet_socktop_safe(&ss), socket_errno());
|
||||
perror("bind");
|
||||
|
|
|
|||
|
|
@ -2139,8 +2139,12 @@ static void startNextProbe(nsock_pool nsp, nsock_iod nsi, ServiceGroup *SG,
|
|||
if (0 == svc->target->SourceSockAddr(&ss, &ss_len)) {
|
||||
// Use the exact protocol-specific length. Some platforms (e.g. FreeBSD)
|
||||
// reject sizeof(sockaddr_storage) passed to bind() with EINVAL.
|
||||
ss_len = (ss.ss_family == AF_INET6) ?
|
||||
sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
|
||||
if (ss.ss_family == AF_INET)
|
||||
ss_len = sizeof(struct sockaddr_in);
|
||||
#if HAVE_IPV6
|
||||
else if (ss.ss_family == AF_INET6)
|
||||
ss_len = sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
nsock_iod_set_localaddr(svc->niod, &ss, ss_len);
|
||||
}
|
||||
if (o.ipoptionslen)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue