From fa448456a9f33d2799d0e7efdd74c2a0d2850933 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Fri, 23 Jul 2021 08:23:29 -0700 Subject: [PATCH] Tests: Add test coverage for sys$unveil(..) argument validation --- Tests/Kernel/TestKernelUnveil.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Tests/Kernel/TestKernelUnveil.cpp b/Tests/Kernel/TestKernelUnveil.cpp index 884bf18314..04d6d9a737 100644 --- a/Tests/Kernel/TestKernelUnveil.cpp +++ b/Tests/Kernel/TestKernelUnveil.cpp @@ -5,8 +5,36 @@ */ #include +#include #include +TEST_CASE(test_argument_validation) +{ + auto res = unveil("/etc", "aaaaaaaaaaaa"); + EXPECT_EQ(res, -1); + EXPECT_EQ(errno, EINVAL); + + res = unveil(nullptr, "r"); + EXPECT_EQ(res, -1); + EXPECT_EQ(errno, EINVAL); + + res = unveil("/etc", nullptr); + EXPECT_EQ(res, -1); + EXPECT_EQ(errno, EINVAL); + + res = unveil("", "r"); + EXPECT_EQ(res, -1); + EXPECT_EQ(errno, EINVAL); + + res = unveil("test", "r"); + EXPECT_EQ(res, -1); + EXPECT_EQ(errno, EINVAL); + + res = unveil("/etc", "f"); + EXPECT_EQ(res, -1); + EXPECT_EQ(errno, EINVAL); +} + TEST_CASE(test_failures) { auto res = unveil("/etc", "r");