[LTP] [PATCH] lack of ENAMETOOLONG testcases for pathnames longer than PATH_MAX
Al Viro
viro@zeniv.linux.org.uk
Tue Jan 13 20:49:36 CET 2026
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.
Ran into that when a braino in kernel patch broke that logics
(ending up with cutoff too low) and that didn't get caught by LTP run.
Patch below adds the checks to one of the tests that do deal
with the other source of ENAMETOOLONG; it almost certainly not the
right use of infrastructure, though.
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},
+ {shorter_path, 0},
};
static void verify_chdir(unsigned int i)
{
- TST_EXP_FAIL(chdir(tcases[i].dir), tcases[i].exp_errno, "chdir()");
+ if (tcases[i].exp_errno)
+ TST_EXP_FAIL(chdir(tcases[i].dir), tcases[i].exp_errno, "chdir()");
+ else
+ TST_EXP_PASS(chdir(tcases[i].dir), "chdir()");
}
static void setup(void)
{
tcases[2].dir = tst_get_bad_addr(NULL);
+ memset(long_path, '/', PATH_MAX);
+ memset(shorter_path, '/', PATH_MAX - 1);
}
static struct tst_test test = {
More information about the ltp
mailing list