You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/08/02 13:12:32 UTC

[nuttx] branch master updated: fs/romfs: Fix FIOC_FILEPATH for dup'ed file

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d563717827 fs/romfs: Fix FIOC_FILEPATH for dup'ed file
d563717827 is described below

commit d563717827148f7ff4bd7e32af8fbecd025768cf
Author: Zhe Weng <we...@xiaomi.com>
AuthorDate: Wed Aug 2 15:11:40 2023 +0800

    fs/romfs: Fix FIOC_FILEPATH for dup'ed file
    
    The FIOC_FILEPATH ioctl needs rf->rf_path, which is not initialized for
    dup'ed romfs file and cause problems.
    
    Signed-off-by: Zhe Weng <we...@xiaomi.com>
---
 fs/romfs/fs_romfs.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c
index 2ba2e69c3f..a151cfa7f2 100644
--- a/fs/romfs/fs_romfs.c
+++ b/fs/romfs/fs_romfs.c
@@ -160,7 +160,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
   struct romfs_nodeinfo_s     nodeinfo;
   FAR struct romfs_mountpt_s *rm;
   FAR struct romfs_file_s    *rf;
-  size_t                      size;
+  size_t                      len;
   int                         ret;
 
   finfo("Open '%s'\n", relpath);
@@ -248,8 +248,8 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
    * file.
    */
 
-  size = strlen(relpath);
-  rf = kmm_zalloc(sizeof(struct romfs_file_s) + size);
+  len = strlen(relpath);
+  rf = kmm_zalloc(sizeof(struct romfs_file_s) + len);
   if (!rf)
     {
       ferr("ERROR: Failed to allocate private data\n");
@@ -263,7 +263,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
 
   rf->rf_size = nodeinfo.rn_size;
   rf->rf_type = (uint8_t)(nodeinfo.rn_next & RFNEXT_ALLMODEMASK);
-  strlcpy(rf->rf_path, relpath, size + 1);
+  strlcpy(rf->rf_path, relpath, len + 1);
 
   /* Get the start of the file data */
 
@@ -644,6 +644,7 @@ static int romfs_dup(FAR const struct file *oldp, FAR struct file *newp)
   FAR struct romfs_mountpt_s *rm;
   FAR struct romfs_file_s *oldrf;
   FAR struct romfs_file_s *newrf;
+  size_t len;
   int ret;
 
   finfo("Dup %p->%p\n", oldp, newp);
@@ -684,7 +685,8 @@ static int romfs_dup(FAR const struct file *oldp, FAR struct file *newp)
    * dup'ed file.
    */
 
-  newrf = kmm_malloc(sizeof(struct romfs_file_s));
+  len   = strlen(oldrf->rf_path);
+  newrf = kmm_malloc(sizeof(struct romfs_file_s) + len);
   if (!newrf)
     {
       ferr("ERROR: Failed to allocate private data\n");
@@ -696,6 +698,8 @@ static int romfs_dup(FAR const struct file *oldp, FAR struct file *newp)
 
   newrf->rf_startoffset = oldrf->rf_startoffset;
   newrf->rf_size        = oldrf->rf_size;
+  newrf->rf_type        = oldrf->rf_type;
+  strlcpy(newrf->rf_path, oldrf->rf_path, len + 1);
 
   /* Configure buffering to support access to this file */