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

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

commit bedf286ae2e48ed5dce45344b8f855f866d0eeae
Author: ligd <[email protected]>
AuthorDate: Wed Nov 11 19:29:29 2026 +0800

    fs: keep FIOC_FILEPATH results terminated
    
    FIOC_FILEPATH fills a caller-provided PATH_MAX buffer, so every
    handler must leave the result NUL-terminated inside it.
    
    littlefs and smartfs append a '/' after inode_getpath() when the
    mount point path lacks one.  When inode_getpath() has filled the
    buffer to PATH_MAX - 1 this overwrites the terminating NUL.  smartfs
    also passes PATH_MAX - len to strlcat(), whose size argument is the
    whole buffer, so a long path is cut len bytes short.
    
    The block never runs for a correctly sized path: filep->f_inode is
    the mount point inode here and inode_getpath() always ends a mount
    point path with '/'.  Drop it, and give strlcat() the buffer size.
    
    A path from this ioctl that was not terminated reached
    notify_queue_path_event() through file_get_path() -> notify_close().
    
    Signed-off-by: ligd <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 fs/littlefs/lfs_vfs.c      | 5 -----
 fs/smartfs/smartfs_smart.c | 9 +--------
 2 files changed, 1 insertion(+), 13 deletions(-)

diff --git a/fs/littlefs/lfs_vfs.c b/fs/littlefs/lfs_vfs.c
index 8cc3c0585e1..1e579a19200 100644
--- a/fs/littlefs/lfs_vfs.c
+++ b/fs/littlefs/lfs_vfs.c
@@ -908,11 +908,6 @@ static int littlefs_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
             {
               size_t len = strlen(path);
 
-              if (path[len - 1] != '/')
-                {
-                  path[len++] = '/';
-                }
-
               ret = littlefs_convert_result(lfs_file_path(&fs->lfs,
                                                           &priv->file,
                                                           path + len,
diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c
index 7a79c8e1256..2a408bb71ff 100644
--- a/fs/smartfs/smartfs_smart.c
+++ b/fs/smartfs/smartfs_smart.c
@@ -1051,14 +1051,7 @@ static int smartfs_ioctl(FAR struct file *filep, int 
cmd, unsigned long arg)
           ret = inode_getpath(inode, path, PATH_MAX);
           if (ret >= 0)
             {
-              size_t len = strlen(path);
-
-              if (path[len - 1] != '/')
-                {
-                  path[len++] = '/';
-                }
-
-              strlcat(path, priv->path, PATH_MAX - len);
+              strlcat(path, priv->path, PATH_MAX);
             }
         }
         break;

Reply via email to