mirror of
https://github.com/nmap/nmap.git
synced 2025-12-18 13:39:02 +00:00
Don't use the clobbered rtmsg->rtm_family to look up interfaces.
This value gets clobbered after the netlink recvmsg. It was giving me a bogus address family (234), which caused the call to getInterfaceByName to fail: Could not find interface wlan0 which was specified by -e This seems to have been exposed by r29754. Specifying a source address that is not on any actual route seems to result in a netlink query result with 0 entries, and the changed value of rtm_family. (The fact that there are no routes returned is not a problem, because we bail out early when -e is given, now that getInterfaceByName works again.)
This commit is contained in:
@@ -3138,14 +3138,14 @@ static int route_dst_netlink(const struct sockaddr_storage *dst,
|
|||||||
struct interface_info *ii;
|
struct interface_info *ii;
|
||||||
ii = NULL;
|
ii = NULL;
|
||||||
if (device != NULL && device[0] != '\0') {
|
if (device != NULL && device[0] != '\0') {
|
||||||
ii = getInterfaceByName(device, rtmsg->rtm_family);
|
ii = getInterfaceByName(device, dst->ss_family);
|
||||||
if (ii == NULL)
|
if (ii == NULL)
|
||||||
netutil_fatal("Could not find interface %s which was specified by -e", device);
|
netutil_fatal("Could not find interface %s which was specified by -e", device);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (rtattr = RTM_RTA(rtmsg); RTA_OK(rtattr, len); rtattr = RTA_NEXT(rtattr, len)) {
|
for (rtattr = RTM_RTA(rtmsg); RTA_OK(rtattr, len); rtattr = RTA_NEXT(rtattr, len)) {
|
||||||
if (rtattr->rta_type == RTA_GATEWAY) {
|
if (rtattr->rta_type == RTA_GATEWAY) {
|
||||||
rc = set_sockaddr(&rnfo->nexthop, rtmsg->rtm_family, RTA_DATA(rtattr));
|
rc = set_sockaddr(&rnfo->nexthop, dst->ss_family, RTA_DATA(rtattr));
|
||||||
assert(rc != -1);
|
assert(rc != -1);
|
||||||
/* Don't consider it directly connected if nexthop != dst. */
|
/* Don't consider it directly connected if nexthop != dst. */
|
||||||
if (!sockaddr_storage_equal(dst, &rnfo->nexthop))
|
if (!sockaddr_storage_equal(dst, &rnfo->nexthop))
|
||||||
@@ -3158,11 +3158,11 @@ static int route_dst_netlink(const struct sockaddr_storage *dst,
|
|||||||
intf_index = *(int *) RTA_DATA(rtattr);
|
intf_index = *(int *) RTA_DATA(rtattr);
|
||||||
p = if_indextoname(intf_index, namebuf);
|
p = if_indextoname(intf_index, namebuf);
|
||||||
assert(p != NULL);
|
assert(p != NULL);
|
||||||
ii = getInterfaceByName(namebuf, rtmsg->rtm_family);
|
ii = getInterfaceByName(namebuf, dst->ss_family);
|
||||||
if (ii == NULL)
|
if (ii == NULL)
|
||||||
netutil_fatal("%s: can't find interface \"%s\"", __func__, namebuf);
|
netutil_fatal("%s: can't find interface \"%s\"", __func__, namebuf);
|
||||||
} else if (rtattr->rta_type == RTA_PREFSRC && rnfo->srcaddr.ss_family == AF_UNSPEC) {
|
} else if (rtattr->rta_type == RTA_PREFSRC && rnfo->srcaddr.ss_family == AF_UNSPEC) {
|
||||||
rc = set_sockaddr(&rnfo->srcaddr, rtmsg->rtm_family, RTA_DATA(rtattr));
|
rc = set_sockaddr(&rnfo->srcaddr, dst->ss_family, RTA_DATA(rtattr));
|
||||||
assert(rc != -1);
|
assert(rc != -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user