summaryrefslogtreecommitdiff
path: root/Tests/Kernel/TestKernelPledge.cpp
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-07-23 09:26:48 -0700
committerAndreas Kling <kling@serenityos.org>2021-07-23 19:02:25 +0200
commitc2282ee28de37380107360318797f20fdc4cc276 (patch)
treeabe1049020245fe664960713a6edf3181306221d /Tests/Kernel/TestKernelPledge.cpp
parente4b86aa5d829c401ab431253964922dfa5b5b8b0 (diff)
downloadserenity-c2282ee28de37380107360318797f20fdc4cc276.zip
Tests: Add test coverage for sys$pledge(..) argument validation
Diffstat (limited to 'Tests/Kernel/TestKernelPledge.cpp')
-rw-r--r--Tests/Kernel/TestKernelPledge.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/Tests/Kernel/TestKernelPledge.cpp b/Tests/Kernel/TestKernelPledge.cpp
index 02f9ce6f9c..3a90450c2e 100644
--- a/Tests/Kernel/TestKernelPledge.cpp
+++ b/Tests/Kernel/TestKernelPledge.cpp
@@ -4,7 +4,9 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/String.h>
#include <LibTest/TestCase.h>
+#include <errno.h>
#include <unistd.h>
TEST_CASE(test_nonexistent_pledge)
@@ -14,6 +16,31 @@ TEST_CASE(test_nonexistent_pledge)
FAIL("Pledging on existent promises should fail.");
}
+TEST_CASE(test_pledge_argument_validation)
+{
+ const auto long_argument = String::repeated('a', 2048);
+
+ auto res = pledge(long_argument.characters(), "stdio");
+ EXPECT_EQ(res, -1);
+ EXPECT_EQ(errno, E2BIG);
+
+ res = pledge("stdio", long_argument.characters());
+ EXPECT_EQ(res, -1);
+ EXPECT_EQ(errno, E2BIG);
+
+ res = pledge(long_argument.characters(), long_argument.characters());
+ EXPECT_EQ(res, -1);
+ EXPECT_EQ(errno, E2BIG);
+
+ res = pledge("fake", "stdio");
+ EXPECT_EQ(res, -1);
+ EXPECT_EQ(errno, EINVAL);
+
+ res = pledge("stdio", "fake");
+ EXPECT_EQ(res, -1);
+ EXPECT_EQ(errno, EINVAL);
+}
+
TEST_CASE(test_pledge_failures)
{
auto res = pledge("stdio unix rpath", "stdio");