Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/net convert program in PR kern/44054 to an atf test case
details: https://anonhg.NetBSD.org/src/rev/5780f27096c9
branches: trunk
changeset: 758550:5780f27096c9
user: pooka <pooka%NetBSD.org@localhost>
date: Sun Nov 07 19:53:42 2010 +0000
description:
convert program in PR kern/44054 to an atf test case
diffstat:
tests/net/Makefile | 4 +-
tests/net/if/Makefile | 13 +++++++
tests/net/if/t_compat.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 98 insertions(+), 2 deletions(-)
diffs (119 lines):
diff -r e3aa9c638367 -r 5780f27096c9 tests/net/Makefile
--- a/tests/net/Makefile Sun Nov 07 19:47:18 2010 +0000
+++ b/tests/net/Makefile Sun Nov 07 19:53:42 2010 +0000
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.6 2010/08/10 21:55:28 pooka Exp $
+# $NetBSD: Makefile,v 1.7 2010/11/07 19:53:42 pooka Exp $
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/net
-TESTS_SUBDIRS= bpf carp icmp if_loop sys
+TESTS_SUBDIRS= bpf carp icmp if if_loop sys
.include <bsd.test.mk>
diff -r e3aa9c638367 -r 5780f27096c9 tests/net/if/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/if/Makefile Sun Nov 07 19:53:42 2010 +0000
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1 2010/11/07 19:53:42 pooka Exp $
+#
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/net/if
+
+TESTS_C= t_compat
+
+LDADD+= -lrumpnet_shmif -lrumpnet_netinet -lrumpnet_net -lrumpnet -lrump
+LDADD+= -lrumpuser -lpthread
+
+.include <bsd.test.mk>
diff -r e3aa9c638367 -r 5780f27096c9 tests/net/if/t_compat.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/if/t_compat.c Sun Nov 07 19:53:42 2010 +0000
@@ -0,0 +1,83 @@
+/* $NetBSD: t_compat.c,v 1.1 2010/11/07 19:53:42 pooka Exp $ */
+
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <netinet/in.h>
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include "../config/netconfig.c"
+
+/*
+ * Test for stack smashing in compat ioctl handling. Adapted as an
+ * atf test from code provided by Onno van der Linden in PR kern/44054
+ */
+
+struct oifreq {
+ char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ union {
+ struct sockaddr ifru_addr;
+ struct sockaddr ifru_dstaddr;
+ struct sockaddr ifru_broadaddr;
+ short ifru_flags;
+ int ifru_metric;
+ int ifru_mtu;
+ int ifru_dlt;
+ u_int ifru_value;
+ void * ifru_data;
+ struct {
+ uint32_t b_buflen;
+ void *b_buf;
+ } ifru_b;
+ } ifr_ifru;
+};
+#define OOSIOCGIFBRDADDR _IOWR('i', 18, struct oifreq)
+
+ATF_TC(OOSIOCGIFBRDADDR);
+ATF_TC_HEAD(OOSIOCGIFBRDADDR, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks that OOSIOCGIFBRDADDR works "
+ "(PR kern/44054)");
+}
+
+ATF_TC_BODY(OOSIOCGIFBRDADDR, tc)
+{
+ int fd, ifnum;
+ struct oifreq ifreq;
+ struct sockaddr_in *sin;
+ int rv;
+
+ memset(&ifreq,'\0',sizeof ifreq);
+
+ rump_init();
+
+ /* create an interface and give it netmask 0xffff0000 */
+ rv = rump_pub_shmif_create("bus", &ifnum);
+ if (rv)
+ atf_tc_fail("failed to create shmif: %s", strerror(rv));
+ sprintf(ifreq.ifr_name, "shmif%d", ifnum);
+ netcfg_rump_if(ifreq.ifr_name, "1.7.64.10", "255.255.0.0");
+
+ /* query kernel for iface bcast */
+ RL(fd = rump_sys_socket(AF_INET, SOCK_DGRAM, 0));
+ RL(rump_sys_ioctl(fd, OOSIOCGIFBRDADDR, &ifreq));
+
+ /* make sure we got what we deserve */
+ sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
+ ATF_REQUIRE_EQ(sin->sin_addr.s_addr, htonl(0x0107ffff));
+ rump_sys_close(fd);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, OOSIOCGIFBRDADDR);
+ return atf_no_error();
+}
Home |
Main Index |
Thread Index |
Old Index