Module Name:    src
Committed By:   pooka
Date:           Mon Aug 16 10:47:16 UTC 2010

Modified Files:
        src/tests/fs/vfs: t_vfsops.c

Log Message:
Add a test case which tries to fhopen() a file handle filled with
random garbage.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/fs/vfs/t_vfsops.c

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

Modified files:

Index: src/tests/fs/vfs/t_vfsops.c
diff -u src/tests/fs/vfs/t_vfsops.c:1.6 src/tests/fs/vfs/t_vfsops.c:1.7
--- src/tests/fs/vfs/t_vfsops.c:1.6	Thu Aug 12 09:42:53 2010
+++ src/tests/fs/vfs/t_vfsops.c	Mon Aug 16 10:47:16 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_vfsops.c,v 1.6 2010/08/12 09:42:53 pooka Exp $	*/
+/*	$NetBSD: t_vfsops.c,v 1.7 2010/08/16 10:47:16 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -165,11 +165,49 @@
 }
 #undef FNAME
 
+/*
+ * This test only checks the file system doesn't crash.  We *might*
+ * try a valid file handle.
+ */
+static void
+tfhinval(const atf_tc_t *tc, const char *path)
+{
+	size_t fhsize;
+	void *fhp;
+	unsigned long seed;
+	int fd;
+
+	if (FSTYPE_TMPFS(tc))
+		atf_tc_skip("file handles broken (PR kern/43605)");
+
+	srandom(seed = time(NULL));
+	printf("RNG seed %lu\n", seed);
+
+	RL(rump_sys_chdir(path));
+	fhsize = 0;
+	if (rump_sys_getfh(".", NULL, &fhsize) == -1) {
+		if (errno == EOPNOTSUPP) {
+			atf_tc_skip("file handles not supported");
+		} else if (errno != E2BIG) {
+			atf_tc_fail_errno("getfh size");
+		}
+	}
+
+	fhp = malloc(fhsize);
+	tests_makegarbage(fhp, fhsize);
+	fd = rump_sys_fhopen(fhp, fhsize, O_RDWR);
+	if (fd != -1)
+		rump_sys_close(fd);
+
+	RL(rump_sys_chdir("/"));
+}
+
 ATF_TC_FSAPPLY(tmount, "mount/unmount");
 ATF_TC_FSAPPLY(tstatvfs, "statvfs");
 ATF_TC_FSAPPLY(tsync, "sync");
 ATF_TC_FSAPPLY(tfilehandle, "file handles");
 ATF_TC_FSAPPLY(tfhremove, "fhtovp for removed file");
+ATF_TC_FSAPPLY(tfhinval, "fhopen invalid filehandle");
 
 ATF_TP_ADD_TCS(tp)
 {
@@ -179,6 +217,7 @@
 	ATF_TP_FSAPPLY(tsync);
 	ATF_TP_FSAPPLY(tfilehandle);
 	ATF_TP_FSAPPLY(tfhremove);
+	ATF_TP_FSAPPLY(tfhinval);
 
 	return atf_no_error();
 }

Reply via email to