[BACK]Return to t_div-by-zero.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / tests / net / bpf

File: [cvs.NetBSD.org] / src / tests / net / bpf / t_div-by-zero.c (download)

Revision 1.4, Fri Mar 1 13:49:42 2013 UTC (8 years, 1 month ago) by pooka
Branch: MAIN
CVS Tags: yamt-pagecache-base9, tls-maxphys-base, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, is-mlppp-base, is-mlppp, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, agc-symver-base, agc-symver, HEAD
Changes since 1.3: +0 -1 lines

Rump kernel hypercalls are not necessary here.

#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/rump_syscalls.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;
	int fd;

	/*
	 * Source code for following program:
	 * link[0:4]/0 = 2
	 */
	struct bpf_insn bins[] = {
	    { 0x20, 0, 0, 0x00000000 },
	    { 0x34, 0, 0, 0x00000000 },
	    { 0x15, 0, 1, 0x00000002 },
	    { 0x6, 0, 0, 0x00000060 },
	    { 0x6, 0, 0, 0x00000000 },
	};

	bp.bf_len = __arraycount(bins);
	bp.bf_insns = bins;

	rump_init();
	fd = rump_sys_open("/dev/bpf", O_RDWR);
	ATF_CHECK(fd != -1);
	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();
}