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 <wangxingxing@xiaomi.com>
This commit is contained in:
wangxingxing 2026-03-24 21:25:04 +08:00 committed by GUIDINGLI
parent 24d371c0fe
commit ea4a4585cd

View file

@ -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 == '/')
{