From 748ad6d00f98633f0f421188a03ecd3eac2c235b Mon Sep 17 00:00:00 2001 From: claudio Date: Sun, 9 Jan 2022 10:36:52 +0000 Subject: [PATCH] Add two test cases from semarie@ which are solved by the last unveil commit. --- regress/sys/kern/unveil/syscalls.c | 39 +++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/regress/sys/kern/unveil/syscalls.c b/regress/sys/kern/unveil/syscalls.c index 4503da86ac8..b09b72c377b 100644 --- a/regress/sys/kern/unveil/syscalls.c +++ b/regress/sys/kern/unveil/syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syscalls.c,v 1.31 2021/12/13 16:56:50 deraadt Exp $ */ +/* $OpenBSD: syscalls.c,v 1.32 2022/01/09 10:36:52 claudio Exp $ */ /* * Copyright (c) 2017-2019 Bob Beck @@ -971,6 +971,41 @@ test_fork_locked(int do_uv) return 1; } +static int +test_intermediate_node(int do_uv) +{ + struct stat st; + + if (do_uv) { + printf("testing unveil on intermediate node\n"); + UV_SHOULD_SUCCEED((unveil("/", "r") == -1), "unveil"); + UV_SHOULD_SUCCEED((unveil("/usr/bin/id", "rx") == -1), + "unveil"); + UV_SHOULD_SUCCEED((unveil(NULL, NULL) == -1), "unveil"); + } + + UV_SHOULD_SUCCEED((stat("/usr/bin", &st) == -1), "stat"); + return 0; +} + +static int +test_noaccess_node(int do_uv) +{ + struct stat st; + + if (do_uv) { + printf("testing unveil on noaccess node\n"); + UV_SHOULD_SUCCEED((unveil("/", "r") == -1), "unveil"); + UV_SHOULD_SUCCEED((unveil("/usr/bin/id", "rx") == -1), + "unveil"); + UV_SHOULD_SUCCEED((unveil("/usr/bin", "") == -1), "unveil"); + UV_SHOULD_SUCCEED((unveil(NULL, NULL) == -1), "unveil"); + } + + UV_SHOULD_ENOENT((stat("/usr/bin", &st) == -1), "stat"); + return 0; +} + int main (int argc, char *argv[]) { @@ -1021,5 +1056,7 @@ main (int argc, char *argv[]) failures += runcompare(test_pathdiscover); failures += runcompare(test_fchdir); failures += runcompare(test_fork_locked); + failures += runcompare(test_intermediate_node); + failures += runcompare(test_noaccess_node); exit(failures); } -- 2.20.1