Home | History | Annotate | Line # | Download | only in bpf
t_div-by-zero.c revision 1.3
      1 #include <sys/types.h>
      2 #include <sys/ioctl.h>
      3 
      4 #include <net/bpf.h>
      5 
      6 #include <atf-c.h>
      7 #include <fcntl.h>
      8 
      9 #include <rump/rump.h>
     10 #include <rump/rumpuser.h>
     11 #include <rump/rump_syscalls.h>
     12 
     13 ATF_TC(div_by_zero);
     14 ATF_TC_HEAD(div_by_zero, tc)
     15 {
     16 
     17 	atf_tc_set_md_var(tc, "descr", "Check that BPF rejects a filter "
     18 	    "which divides by 0");
     19 }
     20 
     21 ATF_TC_BODY(div_by_zero, tc)
     22 {
     23 	struct bpf_program bp;
     24 	int fd;
     25 
     26 	/*
     27 	 * Source code for following program:
     28 	 * link[0:4]/0 = 2
     29 	 */
     30 	struct bpf_insn bins[] = {
     31 	    { 0x20, 0, 0, 0x00000000 },
     32 	    { 0x34, 0, 0, 0x00000000 },
     33 	    { 0x15, 0, 1, 0x00000002 },
     34 	    { 0x6, 0, 0, 0x00000060 },
     35 	    { 0x6, 0, 0, 0x00000000 },
     36 	};
     37 
     38 	bp.bf_len = __arraycount(bins);
     39 	bp.bf_insns = bins;
     40 
     41 	rump_init();
     42 	fd = rump_sys_open("/dev/bpf", O_RDWR);
     43 	ATF_CHECK(fd != -1);
     44 	ATF_REQUIRE_EQ_MSG(rump_sys_ioctl(fd, BIOCSETF, &bp), -1,
     45 	    "bpf accepted program with division by zero");
     46 }
     47 
     48 ATF_TP_ADD_TCS(tp)
     49 {
     50 
     51 	ATF_TP_ADD_TC(tp, div_by_zero);
     52 	return atf_no_error();
     53 }
     54