[LTP] [PATCH] execve: Add negative test for execve

Yang Xu xuyang2018.jy@fujitsu.com
Tue Apr 16 10:01:41 CEST 2024


Add negative case for execve, when errno is ELOOP

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/execve/.gitignore |  1 +
 testcases/kernel/syscalls/execve/execve07.c | 51 +++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 testcases/kernel/syscalls/execve/execve07.c

diff --git a/runtest/syscalls b/runtest/syscalls
index cb2c001a0..9578e991a 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -210,6 +210,7 @@ execve03 execve03
 execve04 execve04
 execve05 execve05 -i 5 -n 32
 execve06 execve06
+execve07 execve07
 execvp01 execvp01
 execveat01 execveat01
 execveat02 execveat02
diff --git a/testcases/kernel/syscalls/execve/.gitignore b/testcases/kernel/syscalls/execve/.gitignore
index fee81faf7..881f75486 100644
--- a/testcases/kernel/syscalls/execve/.gitignore
+++ b/testcases/kernel/syscalls/execve/.gitignore
@@ -7,3 +7,4 @@
 /execve06
 /execve06_child
 /execve_child
+/execve07
diff --git a/testcases/kernel/syscalls/execve/execve07.c b/testcases/kernel/syscalls/execve/execve07.c
new file mode 100644
index 000000000..6571846b9
--- /dev/null
+++ b/testcases/kernel/syscalls/execve/execve07.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that execve(2) fails with
+ *
+ * - ELOOP when too many symbolic links are encountered in filename
+ */
+
+#include "tst_test.h"
+
+#define TEST_ELOOP "test_eloop"
+#define TEST_ELOOP2 "test_eloop2"
+
+static struct test_case_t {
+	char *filename;
+	int expected_errno;
+	int user;
+	char *desc;
+} tcases[] = {
+	{TEST_ELOOP, ELOOP, 0,
+		"too many symbolic links are encountered in filename"},
+};
+
+static void setup(void)
+{
+	SAFE_SYMLINK(TEST_ELOOP, TEST_ELOOP2);
+	SAFE_SYMLINK(TEST_ELOOP2, TEST_ELOOP);
+}
+
+static void verify_execve(unsigned int i)
+{
+	struct test_case_t *tc = &tcases[i];
+	char *argv[2] = {tc->filename, NULL};
+
+	TST_EXP_FAIL(execve(tc->filename, argv, NULL), tc->expected_errno,
+		"%s", tc->desc);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_execve,
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+};
-- 
2.39.3



More information about the ltp mailing list