[patch] Verify that ifaddr_byindex(foo) != NULL

Colin Percival colin.percival at wadham.ox.ac.uk
Tue May 4 05:42:25 PDT 2004


  Could someone confirm for me that this looks sensible?  I don't
know anything about this code, but if we're going to check that
0 < ifp->if_index <= if_index, it seems that we should also be
checking that ifp->if_index corresponds to an interface which
still exists (rather than a gap left behind when an interface was
removed).

Colin Percival

Index: src/sys/netinet/ip_input.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ip_input.c,v
retrieving revision 1.270
diff -u -p -r1.270 ip_input.c
--- src/sys/netinet/ip_input.c	2 May 2004 15:10:16 -0000	1.270
+++ src/sys/netinet/ip_input.c	4 May 2004 12:37:02 -0000
@@ -2053,7 +2053,8 @@ ip_savecontrol(inp, mp, ip, m)
 		struct sockaddr_dl *sdl2 = &sdlbuf.sdl;

 		if (((ifp = m->m_pkthdr.rcvif))
-		&& ( ifp->if_index && (ifp->if_index <= if_index))) {
+		&& ( ifp->if_index && (ifp->if_index <= if_index)) &&
+		    (ifaddr_byindex(ifp->if_index) != NULL)) {
 			sdp = (struct sockaddr_dl *)
 			    (ifaddr_byindex(ifp->if_index)->ifa_addr);
 			/*



More information about the freebsd-net mailing list