Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet Don't use a pointer before it is initialized.



details:   https://anonhg.NetBSD.org/src/rev/99ca2476285a
branches:  trunk
changeset: 533208:99ca2476285a
user:      enami <enami%NetBSD.org@localhost>
date:      Mon Jun 24 10:52:15 2002 +0000

description:
Don't use a pointer before it is initialized.

diffstat:

 sys/netinet/if_arp.c |  19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diffs (55 lines):

diff -r 40e40da872a2 -r 99ca2476285a sys/netinet/if_arp.c
--- a/sys/netinet/if_arp.c      Mon Jun 24 10:10:17 2002 +0000
+++ b/sys/netinet/if_arp.c      Mon Jun 24 10:52:15 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.c,v 1.83 2002/06/24 08:42:33 itojun Exp $       */
+/*     $NetBSD: if_arp.c,v 1.84 2002/06/24 10:52:15 enami Exp $        */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -79,7 +79,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.83 2002/06/24 08:42:33 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.84 2002/06/24 10:52:15 enami Exp $");
 
 #include "opt_ddb.h"
 #include "opt_inet.h"
@@ -775,6 +775,13 @@
 
                arpstat.as_rcvtotal++;
 
+               /*
+                * First, make sure we have at least struct arphdr.
+                */
+               if (m->m_len < sizeof(struct arphdr) ||
+                   (ar = mtod(m, struct arphdr *)) == NULL)
+                       goto badlen;
+
                switch (m->m_pkthdr.rcvif->if_type) {
                case IFT_IEEE1394:
                        arplen = sizeof(struct arphdr) +
@@ -786,9 +793,7 @@
                        break;
                }
 
-               if (m->m_len >= sizeof(struct arphdr) &&
-                   (ar = mtod(m, struct arphdr *)) &&
-                   /* XXX ntohs(ar->ar_hrd) == ARPHRD_ETHER && */
+               if (/* XXX ntohs(ar->ar_hrd) == ARPHRD_ETHER && */
                    m->m_len >= arplen)
                        switch (ntohs(ar->ar_pro)) {
                        case ETHERTYPE_IP:
@@ -798,8 +803,10 @@
                        default:
                                arpstat.as_rcvbadproto++;
                        }
-               else
+               else {
+badlen:
                        arpstat.as_rcvbadlen++;
+               }
                m_freem(m);
        }
 }



Home | Main Index | Thread Index | Old Index