Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/net Check that bpf doesn't accept programs with divide...
details: https://anonhg.NetBSD.org/src/rev/d76ce7a00cdf
branches: trunk
changeset: 754127:d76ce7a00cdf
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Apr 21 11:07:34 2010 +0000
description:
Check that bpf doesn't accept programs with divide-by-zero in them.
Example filter from Guy Harris via PR kern/43185.
diffstat:
tests/net/Makefile | 4 +-
tests/net/bpf/Atffile | 6 +++++
tests/net/bpf/Makefile | 13 +++++++++++
tests/net/bpf/t_div-by-zero.c | 48 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 69 insertions(+), 2 deletions(-)
diffs (95 lines):
diff -r 6c435bfdc08f -r d76ce7a00cdf tests/net/Makefile
--- a/tests/net/Makefile Wed Apr 21 07:35:12 2010 +0000
+++ b/tests/net/Makefile Wed Apr 21 11:07:34 2010 +0000
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.1 2007/12/23 13:50:22 jmmv Exp $
+# $NetBSD: Makefile,v 1.2 2010/04/21 11:07:34 pooka Exp $
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/net
-SUBDIR= sys
+SUBDIR= bpf sys
.include <bsd.test.mk>
.include <bsd.subdir.mk>
diff -r 6c435bfdc08f -r d76ce7a00cdf tests/net/bpf/Atffile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/bpf/Atffile Wed Apr 21 11:07:34 2010 +0000
@@ -0,0 +1,6 @@
+Content-Type: application/X-atf-atffile; version="1"
+X-NetBSD-Id: "$NetBSD: Atffile,v 1.1 2010/04/21 11:07:34 pooka Exp $"
+
+prop: test-suite = "NetBSD"
+
+tp-glob: *
diff -r 6c435bfdc08f -r d76ce7a00cdf tests/net/bpf/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/bpf/Makefile Wed Apr 21 11:07:34 2010 +0000
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1 2010/04/21 11:07:34 pooka Exp $
+#
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/net/bpf
+
+TESTS_C= t_div-by-zero
+
+LDADD+= -lrumpdev_bpf -lrumpdev -lrumpnet_net -lrumpnet -lrumpvfs
+LDADD+= -lrump -lrumpuser -lpthread
+
+.include <bsd.test.mk>
diff -r 6c435bfdc08f -r d76ce7a00cdf tests/net/bpf/t_div-by-zero.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/bpf/t_div-by-zero.c Wed Apr 21 11:07:34 2010 +0000
@@ -0,0 +1,48 @@
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include <net/bpf.h>
+
+#include <atf-c.h>
+#include <fcntl.h>
+
+#include <rump/rump.h>
+#include <rump/rumpuser.h>
+
+ATF_TC(div_by_zero);
+ATF_TC_HEAD(div_by_zero, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Check that BPF rejects a filter "
+ "which divides by 0");
+}
+
+ATF_TC_BODY(div_by_zero, tc)
+{
+ struct bpf_program bp;
+ struct bpf_insn bins[] = {
+ { 0x20, 0, 0, 0x00000000 },
+ { 0x34, 0, 0, 0x00000000 },
+ { 0x15, 0, 1, 0x00000002 },
+ { 0x6, 0, 0, 0x00000060 },
+ { 0x6, 0, 0, 0x00000000 },
+ };
+ int fd;
+
+ bp.bf_len = __arraycount(bins);
+ bp.bf_insns = bins;
+
+ rump_init();
+ fd = rump_sys_open("/dev/bpf", O_RDWR);
+ if (fd == -1)
+ err(1, "open bpf");
+ ATF_REQUIRE_EQ_MSG(rump_sys_ioctl(fd, BIOCSETF, &bp), -1,
+ "bpf accepted program with division by zero");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, div_by_zero);
+ return atf_no_error();
+}
Home |
Main Index |
Thread Index |
Old Index