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

Cyril Hrubis chrubis@suse.cz
Wed Aug 21 12:30:30 CEST 2024


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?

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list