diff options
author | Bob Beck <beck@cvs.openbsd.org> | 2019-09-08 22:43:15 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 2019-09-08 22:43:15 +0000 |
commit | effb3ed04ba56c384ac0edda66f775bb3d8d866a (patch) | |
tree | fc0eadddbf1aaaff594ef8c68986e56f314a17c2 /regress | |
parent | 68b26c1b8535381388cade19b6a8d260491f3784 (diff) |
Pull out and expand openat tests into their own routine.
Diffstat (limited to 'regress')
-rw-r--r-- | regress/sys/kern/unveil/syscalls.c | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/regress/sys/kern/unveil/syscalls.c b/regress/sys/kern/unveil/syscalls.c index 650f698c061..813fd7e5c04 100644 --- a/regress/sys/kern/unveil/syscalls.c +++ b/regress/sys/kern/unveil/syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syscalls.c,v 1.23 2019/05/15 21:05:55 beck Exp $ */ +/* $OpenBSD: syscalls.c,v 1.24 2019/09/08 22:43:14 beck Exp $ */ /* * Copyright (c) 2017-2019 Bob Beck <beck@openbsd.org> @@ -129,6 +129,58 @@ runcompare(int (*func)(int)) return runcompare_internal(func, 1); } + +static int +test_openat(int do_uv) +{ + int slashbefore; + int dirfd1before; + int dirfd2before; + int dirfd1after; + int dirfd2after; + UV_SHOULD_SUCCEED(((slashbefore = open("/", O_RDONLY | O_DIRECTORY)) == -1), "open"); + UV_SHOULD_SUCCEED(((dirfd1before = open(uv_dir1, O_RDONLY | O_DIRECTORY)) == -1), "open"); + UV_SHOULD_SUCCEED(((dirfd2before = open(uv_dir2, O_RDONLY | O_DIRECTORY)) == -1), "open"); + if (do_uv) { + printf("testing openat\n"); + do_unveil(); + } + UV_SHOULD_SUCCEED(((dirfd1after = open(uv_dir1, O_RDONLY | O_DIRECTORY)) == -1), "open"); + UV_SHOULD_ENOENT(((dirfd2after = open(uv_dir2, O_RDONLY | O_DIRECTORY)) == -1), "open"); + + UV_SHOULD_ENOENT((openat(slashbefore, "etc/hosts", O_RDONLY) == -1), "openat"); + UV_SHOULD_ENOENT((openat(slashbefore, "hooray", O_RDWR|O_CREAT) == -1), "openat"); + UV_SHOULD_SUCCEED((openat(slashbefore, uv_file1, O_RDWR) == -1), "openat"); + UV_SHOULD_ENOENT((openat(slashbefore, uv_file2, O_RDWR) == -1), "openat"); + + UV_SHOULD_ENOENT((openat(dirfd1before, "/etc/hosts", O_RDONLY) == -1), "openat"); + UV_SHOULD_SUCCEED((openat(dirfd1before, "hooray", O_RDWR|O_CREAT) == -1), "openat"); + UV_SHOULD_SUCCEED((openat(dirfd1before, uv_file1, O_RDWR|O_CREAT) == -1), "openat"); + UV_SHOULD_ENOENT((openat(dirfd1before, uv_file2, O_RDWR|O_CREAT) == -1), "openat"); + + UV_SHOULD_ENOENT((openat(dirfd2before, "/etc/hosts", O_RDONLY) == -1), "openat"); + UV_SHOULD_ENOENT((openat(dirfd2before, "hooray", O_RDWR|O_CREAT) == -1), "openat"); + UV_SHOULD_SUCCEED((openat(dirfd2before, uv_file1, O_RDWR|O_CREAT) == -1), "openat"); + UV_SHOULD_ENOENT((openat(dirfd2before, uv_file2, O_RDWR|O_CREAT) == -1), "openat"); + + UV_SHOULD_ENOENT((openat(dirfd1after, "/etc/hosts", O_RDONLY) == -1), "openat"); + UV_SHOULD_SUCCEED((openat(dirfd1after, "hooray", O_RDWR|O_CREAT) == -1), "openat"); + UV_SHOULD_SUCCEED((openat(dirfd1after, uv_file1, O_RDWR|O_CREAT) == -1), "openat"); + UV_SHOULD_ENOENT((openat(dirfd1after, uv_file2, O_RDWR|O_CREAT) == -1), "openat"); + + UV_SHOULD_SUCCEED(((dirfd2after = openat(dirfd1after, "subdir", O_RDONLY | O_DIRECTORY)) == -1), "openat"); + UV_SHOULD_SUCCEED((openat(dirfd2after, "../derp", O_RDWR|O_CREAT) == -1), "openat"); + UV_SHOULD_ENOENT((openat(dirfd2after, "../../derpyluvs", O_RDWR|O_CREAT) == -1), "openat"); + UV_SHOULD_ENOENT((openat(dirfd2after, "/etc/hosts", O_RDONLY) == -1), "openat"); + /* XXX won't work until fix in */ + /* UV_SHOULD_SUCCEED((openat(dirfd2after, "hooray", O_RDWR|O_CREAT) == -1), "openat"); */ + UV_SHOULD_SUCCEED((openat(dirfd2after, uv_file1, O_RDWR|O_CREAT) == -1), "openat"); + UV_SHOULD_ENOENT((openat(dirfd2after, uv_file2, O_RDWR|O_CREAT) == -1), "openat"); + return 0; +} + + + static int test_open(int do_uv) { @@ -141,7 +193,7 @@ test_open(int do_uv) UV_SHOULD_SUCCEED(((dirfd = open("/", O_RDONLY | O_DIRECTORY)) == -1), "open"); UV_SHOULD_SUCCEED(((dirfd2 = open(uv_dir2, O_RDONLY | O_DIRECTORY)) == -1), "open"); if (do_uv) { - printf("testing open and openat\n"); + printf("testing open\n"); do_unveil(); if (unveil("/tmp/alpha", uv_flags) == -1) err(1, "%s:%d - unveil", __FILE__, __LINE__); @@ -209,9 +261,6 @@ test_open(int do_uv) } sleep(1); UV_SHOULD_SUCCEED((open(uv_file1, O_RDWR) == -1), "open"); - UV_SHOULD_ENOENT((openat(dirfd, "etc/hosts", O_RDONLY) == -1), "openat"); - UV_SHOULD_ENOENT((openat(dirfd, uv_file2, O_RDWR) == -1), "openat"); - UV_SHOULD_ENOENT((openat(dirfd2, "hooray", O_RDWR|O_CREAT) == -1), "openat"); UV_SHOULD_ENOENT((open(uv_file2, O_RDWR) == -1), "open"); (void) snprintf(filename, sizeof(filename), "%s/%s", uv_dir1, "newfile"); UV_SHOULD_SUCCEED((open(filename, O_RDWR|O_CREAT) == -1), "open"); @@ -272,7 +321,6 @@ test_realpath(int do_uv) do_unveil(); } UV_SHOULD_SUCCEED((realpath(uv_dir1, buf) == NULL), "realpath"); - return 0; UV_SHOULD_ENOENT((realpath(uv_dir2, buf) == NULL), "realpath"); return 0; } @@ -488,7 +536,7 @@ test_parent_dir(int do_uv) UV_SHOULD_SUCCEED((chdir("../../doof/subdir1") == -1), "chdir"); UV_SHOULD_SUCCEED((access("poop", R_OK) == -1), "access"); UV_SHOULD_SUCCEED((access("../subdir1/poop", R_OK) == -1), "access"); - UV_SHOULD_ENOENT((chdir("../../../") == -1), "chdir"); + UV_SHOULD_ENOENT((chdir("../../..") == -1), "chdir"); UV_SHOULD_ENOENT((chdir(uv_dir2) == -1), "chdir"); return(0); } @@ -888,6 +936,7 @@ main (int argc, char *argv[]) close(fd2); failures += runcompare(test_open); + failures += runcompare(test_openat); failures += runcompare(test_opendir); failures += runcompare(test_noflags); failures += runcompare(test_drounveil); |