diff mbox series

execve: Add negative test for execve

Message ID 20240416080141.22616-1-xuyang2018.jy@fujitsu.com
State New
Headers show
Series execve: Add negative test for execve | expand

Commit Message

Yang Xu \(Fujitsu\) April 16, 2024, 8:01 a.m. UTC
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

Comments

Cyril Hrubis Aug. 21, 2024, 10:30 a.m. UTC | #1
Hi!
> +/*\
> + * [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,
> +};

Any reason why this isn't added to execve03.c instead?
Petr Vorel Oct. 21, 2024, 12:52 p.m. UTC | #2
Hi Yang Xu,

> Hi!
> > +/*\
> > + * [Description]
> > + *
> > + * Verify that execve(2) fails with
> > + *
> > + * - ELOOP when too many symbolic links are encountered in filename
> > + */

...

> Any reason why this isn't added to execve03.c instead?

ping please?

Kind regards,
Petr
diff mbox series

Patch

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,
+};