Module Name:    src
Committed By:   pooka
Date:           Thu Mar 10 10:11:25 UTC 2011

Modified Files:
        src/usr.bin/shmif_dumpbus: shmif_dumpbus.c

Log Message:
Add some asserts to make sure the bus offset isn't beyond what we
mapped.  (I had a very interesting time last night trying to figure
out what was going when things apparently got compiled with a 64bit
time_t on nb5.  this caused only 4k of the bus file to be mapped...)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/shmif_dumpbus/shmif_dumpbus.c

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

Modified files:

Index: src/usr.bin/shmif_dumpbus/shmif_dumpbus.c
diff -u src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.2 src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.3
--- src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.2	Wed Mar  9 12:56:08 2011
+++ src/usr.bin/shmif_dumpbus/shmif_dumpbus.c	Thu Mar 10 10:11:25 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmif_dumpbus.c,v 1.2 2011/03/09 12:56:08 pooka Exp $	*/
+/*	$NetBSD: shmif_dumpbus.c,v 1.3 2011/03/10 10:11:25 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -158,21 +158,26 @@
 		uint32_t oldoff;
 		bool wrap;
 
+		assert(curbus < sb.st_size);
+
 		wrap = false;
 		oldoff = curbus;
 		curbus = shmif_busread(bmem, &sp, oldoff, sizeof(sp), &wrap);
 		if (wrap)
 			bonus = 0;
 
-		if (sp.sp_len == 0)
+		assert(curbus < sb.st_size);
+
+		if (sp.sp_len == 0) {
 			continue;
+		}
 
 		if (pfd != STDOUT_FILENO)
 			printf("packet %d, offset 0x%04x, length 0x%04x, "
 			    "ts %d/%06d\n", i++, curbus,
 			    sp.sp_len, sp.sp_sec, sp.sp_usec);
 
-		if (!pcapfile || sp.sp_len == 0) {
+		if (!pcapfile) {
 			curbus = shmif_busread(bmem,
 			    buf, curbus, sp.sp_len, &wrap);
 			if (wrap)
@@ -184,6 +189,7 @@
 		packhdr.caplen = packhdr.len = sp.sp_len;
 		packhdr.ts.tv_sec = sp.sp_sec;
 		packhdr.ts.tv_usec = sp.sp_usec;
+		assert(sp.sp_len <= BUFSIZE);
 
 		if (write(pfd, &packhdr, sizeof(packhdr)) != sizeof(packhdr))
 			err(1, "error writing packethdr");

Reply via email to