net/interfaces: don't dereference null pointer if no destination/netmask

Fixes #6065

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: I7159b8cbb8d5f47c0668cf83e59167f182f1defd
pull/6078/head
Andrew Dunham 2 years ago
parent 19b5586573
commit 95f3dd1346

@ -126,19 +126,24 @@ func isDefaultGateway(rm *route.RouteMessage) bool {
dst := rm.Addrs[unix.RTAX_DST] dst := rm.Addrs[unix.RTAX_DST]
netmask := rm.Addrs[unix.RTAX_NETMASK] netmask := rm.Addrs[unix.RTAX_NETMASK]
if dst == nil || netmask == nil {
return false
}
if dst.Family() == syscall.AF_INET && if dst.Family() == syscall.AF_INET && netmask.Family() == syscall.AF_INET {
netmask.Family() == syscall.AF_INET && dstAddr, dstOk := dst.(*route.Inet4Addr)
dst.(*route.Inet4Addr).IP == v4default && nmAddr, nmOk := netmask.(*route.Inet4Addr)
netmask.(*route.Inet4Addr).IP == v4default { if dstOk && nmOk && dstAddr.IP == v4default && nmAddr.IP == v4default {
return true return true
}
} }
if dst.Family() == syscall.AF_INET6 && if dst.Family() == syscall.AF_INET6 && netmask.Family() == syscall.AF_INET6 {
netmask.Family() == syscall.AF_INET6 && dstAddr, dstOk := dst.(*route.Inet6Addr)
dst.(*route.Inet6Addr).IP == v6default && nmAddr, nmOk := netmask.(*route.Inet6Addr)
netmask.(*route.Inet6Addr).IP == v6default { if dstOk && nmOk && dstAddr.IP == v6default && nmAddr.IP == v6default {
return true return true
}
} }
return false return false

Loading…
Cancel
Save