summaryrefslogtreecommitdiffstats
path: root/usr.sbin/tcpdump/print-ip.c
diff options
context:
space:
mode:
authorcanacar <canacar@openbsd.org>2007-06-27 18:15:25 +0000
committercanacar <canacar@openbsd.org>2007-06-27 18:15:25 +0000
commit620a734dd6b585f88f2c80c6aee1a17685c4e4ae (patch)
treec969399b3f491db1c7453f898902ecd826ad7a0a /usr.sbin/tcpdump/print-ip.c
parentAccording to Intel errata: (diff)
downloadwireguard-openbsd-620a734dd6b585f88f2c80c6aee1a17685c4e4ae.tar.xz
wireguard-openbsd-620a734dd6b585f88f2c80c6aee1a17685c4e4ae.zip
When aligning buffers correctly handle the case where the
buffers overlap, which happens on 64 bit archs, when handling encapsulated packets. Reported and tested by Jurjen Oskam additional testing by Stuart Henderson and todd@, ok henning@
Diffstat (limited to 'usr.sbin/tcpdump/print-ip.c')
-rw-r--r--usr.sbin/tcpdump/print-ip.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/usr.sbin/tcpdump/print-ip.c b/usr.sbin/tcpdump/print-ip.c
index 22075ec1755..fb7d5bf0858 100644
--- a/usr.sbin/tcpdump/print-ip.c
+++ b/usr.sbin/tcpdump/print-ip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print-ip.c,v 1.32 2006/06/01 17:18:39 moritz Exp $ */
+/* $OpenBSD: print-ip.c,v 1.33 2007/06/27 18:15:25 canacar Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -23,7 +23,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /home/cvs/src/usr.sbin/tcpdump/print-ip.c,v 1.32 2006/06/01 17:18:39 moritz Exp $ (LBL)";
+ "@(#) $Header: /home/cvs/src/usr.sbin/tcpdump/print-ip.c,v 1.33 2007/06/27 18:15:25 canacar Exp $ (LBL)";
#endif
#include <sys/param.h>
@@ -373,14 +373,17 @@ ip_print(register const u_char *bp, register u_int length)
if ((intptr_t)ip & (sizeof(long)-1)) {
static u_char *abuf = NULL;
static int didwarn = 0;
+ int clen = snapend - bp;
+ if (clen > snaplen)
+ clen = snaplen;
if (abuf == NULL) {
abuf = (u_char *)malloc(snaplen);
if (abuf == NULL)
error("ip_print: malloc");
}
- memcpy((char *)abuf, (char *)ip, min(length, snaplen));
- snapend += abuf - (u_char *)ip;
+ memmove((char *)abuf, (char *)ip, min(length, clen));
+ snapend = abuf + clen;
packetp = abuf;
ip = (struct ip *)abuf;
/* We really want libpcap to give us aligned packets */