From ea4a4585cda331e156774c6b1326bf894ac385e2 Mon Sep 17 00:00:00 2001 From: wangxingxing Date: Tue, 24 Mar 2026 21:25:04 +0800 Subject: [PATCH] fs/inode: fix off-by-one error in _inode_checkpath NAME_MAX check The _inode_checkpath function uses `namelen < NAME_MAX` to validate path segment lengths. When a filename is exactly NAME_MAX characters long and is followed by more path segments (e.g. /dir/), the loop exits with namelen == NAME_MAX before processing the '/' separator, causing a spurious ENAMETOOLONG error. Per POSIX, NAME_MAX is the maximum number of bytes in a filename not including the terminating null, so a filename of exactly NAME_MAX characters is valid. Change the condition to `namelen <= NAME_MAX` so the loop can process the trailing '/' separator and correctly reset namelen for the next path segment. Signed-off-by: wangxingxing --- fs/inode/fs_inodesearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/inode/fs_inodesearch.c b/fs/inode/fs_inodesearch.c index 2f01a63c485..c700e61234d 100644 --- a/fs/inode/fs_inodesearch.c +++ b/fs/inode/fs_inodesearch.c @@ -256,7 +256,7 @@ static int _inode_checkpath(const char *path) /* Check each segment of the path */ - while (*path != '\0' && namelen < NAME_MAX && pathlen < PATH_MAX) + while (*path != '\0' && namelen <= NAME_MAX && pathlen < PATH_MAX) { if (*path == '/') {