Module Name:    src
Committed By:   maxv
Date:           Thu May 17 11:59:36 UTC 2018

Modified Files:
        src/sys/netinet: ip_input.c
        src/sys/netinet6: ip6_input.c

Log Message:
Add KASSERTs, related to PR/39794.


To generate a diff of this commit:
cvs rdiff -u -r1.383 -r1.384 src/sys/netinet/ip_input.c
cvs rdiff -u -r1.202 -r1.203 src/sys/netinet6/ip6_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.383 src/sys/netinet/ip_input.c:1.384
--- src/sys/netinet/ip_input.c:1.383	Mon May 14 17:34:26 2018
+++ src/sys/netinet/ip_input.c	Thu May 17 11:59:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.383 2018/05/14 17:34:26 maxv Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.384 2018/05/17 11:59:36 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.383 2018/05/14 17:34:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.384 2018/05/17 11:59:36 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -587,8 +587,10 @@ ip_input(struct mbuf *m)
 			m = NULL;
 			goto out;
 		}
+		KASSERT(m->m_len >= sizeof(struct ip));
 		ip = mtod(m, struct ip *);
 		hlen = ip->ip_hl << 2;
+		KASSERT(m->m_len >= hlen);
 
 		/*
 		 * XXX The setting of "srcrt" here is to prevent ip_forward()

Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.202 src/sys/netinet6/ip6_input.c:1.203
--- src/sys/netinet6/ip6_input.c:1.202	Mon May 14 17:34:26 2018
+++ src/sys/netinet6/ip6_input.c	Thu May 17 11:59:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.202 2018/05/14 17:34:26 maxv Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.203 2018/05/17 11:59:36 maxv Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.202 2018/05/14 17:34:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.203 2018/05/17 11:59:36 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -354,6 +354,7 @@ ip6_input(struct mbuf *m, struct ifnet *
 			return;
 		if (m == NULL)
 			return;
+		KASSERT(m->m_len >= sizeof(struct ip6_hdr));
 		ip6 = mtod(m, struct ip6_hdr *);
 		srcrt = !IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst);
 	}

Reply via email to