This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit ea4a4585cda331e156774c6b1326bf894ac385e2
Author: wangxingxing <[email protected]>
AuthorDate: Tue Mar 24 21:25:04 2026 +0800

    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 <[email protected]>
---
 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 == '/')
         {

Reply via email to