diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2022-02-07 15:23:44 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2022-02-07 15:23:44 +0000 |
commit | e3869c635618b6b8331ec10cb1c3d77a07aeaf91 (patch) | |
tree | 7cfa3ccc34da38105c09c1f888336ca3d33bf95e /sys/netinet6/nd6.c | |
parent | b0066b1c78b4e77036329b93d55e8963e3826e30 (diff) |
Checking ifaddr pointer for NULL without checking in6_ifaddr works
as ifaddr ia_ifa is the first field of in6_ifaddr. So the pointers
are the same, and one NULL check works for both. But in ISO C NULL
has some kind of type and this is undefined behavior. So add a
second NULL check that the compiler can optimize away. The resulting
assembler is the same.
found by kubsan; OK tobhe@
Diffstat (limited to 'sys/netinet6/nd6.c')
-rw-r--r-- | sys/netinet6/nd6.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 70acc36fcc0..3cfa93dd685 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.236 2021/11/07 19:38:25 sthen Exp $ */ +/* $OpenBSD: nd6.c,v 1.237 2022/02/07 15:23:43 bluhm Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -792,6 +792,7 @@ nd6_rtrequest(struct ifnet *ifp, int req, struct rtentry *rt) struct sockaddr *gate = rt->rt_gateway; struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo; struct ifaddr *ifa; + struct in6_ifaddr *ifa6; if (ISSET(rt->rt_flags, RTF_GATEWAY|RTF_MULTICAST|RTF_MPLS)) return; @@ -944,8 +945,9 @@ nd6_rtrequest(struct ifnet *ifp, int req, struct rtentry *rt) * check if rt_key(rt) is one of my address assigned * to the interface. */ - ifa = &in6ifa_ifpwithaddr(ifp, - &satosin6(rt_key(rt))->sin6_addr)->ia_ifa; + ifa6 = in6ifa_ifpwithaddr(ifp, + &satosin6(rt_key(rt))->sin6_addr); + ifa = ifa6 ? &ifa6->ia_ifa : NULL; if (ifa) { ln->ln_state = ND6_LLINFO_REACHABLE; ln->ln_byhint = 0; |