[LTP] [PATCH] lack of ENAMETOOLONG testcases for pathnames longer than PATH_MAX
Cyril Hrubis
chrubis@suse.cz
Wed Jan 14 10:40:43 CET 2026
Hi!
> There are different causes of ENAMETOOLONG. It might come from
> filesystem rejecting an excessively long pathname component, but there's
> also "pathname is longer than PATH_MAX bytes, including terminating NUL"
> and that doesn't get checked anywhere.
We do have a couple of tests that checks that names over PATH_MAX are
rejected, there is no reason to add these kind of tests, however I do
not think that we tests that check that names that are just under the
limit work fine, that needs to be added.
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
> diff --git a/testcases/kernel/syscalls/chdir/chdir04.c b/testcases/kernel/syscalls/chdir/chdir04.c
> index 6e53b7fef..e8dd5121d 100644
> --- a/testcases/kernel/syscalls/chdir/chdir04.c
> +++ b/testcases/kernel/syscalls/chdir/chdir04.c
> @@ -11,6 +11,8 @@
> #include "tst_test.h"
>
> static char long_dir[] = "abcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz";
> +static char long_path[PATH_MAX+1];
> +static char shorter_path[PATH_MAX];
> static char noexist_dir[] = "noexistdir";
>
> static struct tcase {
> @@ -20,16 +22,23 @@ static struct tcase {
> {long_dir, ENAMETOOLONG},
> {noexist_dir, ENOENT},
> {0, EFAULT}, // bad_addr
> + {long_path, ENAMETOOLONG},
This test already exists in the form of long_dir just three lines above.
> + {shorter_path, 0},
What about we add a separate test (chdir02.c) for paths that shouldn't
be rejected. Something as:
char path[PATH_MAX];
int i;
...
for (i = 1; i < PATH_MAX; i++) {
memset(path, 0, sizeof(path));
memset(path, '/', i);
TST_EXP_PASS(chdir(path), "chdir() len=%i", i);
}
...
That would make sure that all lenghts of paths that are valid are
accepted.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list