sys/net/if.c and bpf.c have problems with if_detach() and
bpfdetach() when they are called with a struct ifnet that has not had
if_attach() and bpfattach() called on it.  Null pointer reference ->
*boom* etc.

This patch fixes the test already present in bpfdetach() and adds a test
to if_detach().

Thanks.

-- 
| Matthew N. Dodd  | '78 Datsun 280Z | '75 Volvo 164E | FreeBSD/NetBSD  |
| [EMAIL PROTECTED] |       2 x '84 Volvo 245DL        | ix86,sparc,pmax |
| http://www.jurai.net/~winter |  For Great Justice!  | ISO8802.5 4ever |
Index: if.c
===================================================================
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.116
diff -u -r1.116 if.c
--- if.c        18 Sep 2001 17:41:42 -0000      1.116
+++ if.c        23 Sep 2001 09:17:11 -0000
@@ -248,6 +248,14 @@
         * Remove routes and flush queues.
         */
        s = splnet();
+
+       if (ifp->if_index == 0) {
+               splx(s);
+               printf("if_detach: %s%d was not attached\n", ifp->if_name,
+                   ifp->if_unit);
+               return;
+       }
+
        if_down(ifp);
 
        /*
Index: bpf.c
===================================================================
RCS file: /cvs/src/sys/net/bpf.c,v
retrieving revision 1.82
diff -u -r1.82 bpf.c
--- bpf.c       21 Sep 2001 22:46:54 -0000      1.82
+++ bpf.c       23 Sep 2001 03:58:04 -0000
@@ -1264,7 +1264,7 @@
        }
 
        /* Interface wasn't attached */
-       if (bp->bif_ifp == NULL) {
+       if (bp == NULL) {
                mtx_unlock(&bpf_mtx);
                printf("bpfdetach: %s%d was not attached\n", ifp->if_name,
                    ifp->if_unit);

Reply via email to