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

acassis 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 d63034994e fs/inode: check file list before memcpy
d63034994e is described below

commit d63034994ed1e72ea0192c6b17d3f3d63c8b6fb0
Author: chao an <anc...@xiaomi.com>
AuthorDate: Tue Nov 14 23:58:25 2023 +0800

    fs/inode: check file list before memcpy
    
    The file list is NULL if task group initialized, check the validity
    of the file list before memcpy.
    
    Signed-off-by: chao an <anc...@xiaomi.com>
---
 fs/inode/fs_files.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c
index 48482526fa..e61728832f 100644
--- a/fs/inode/fs_files.c
+++ b/fs/inode/fs_files.c
@@ -151,8 +151,11 @@ static int files_extend(FAR struct filelist *list, size_t 
row)
       return OK;
     }
 
-  memcpy(files, list->fl_files,
-         list->fl_rows * sizeof(FAR struct file *));
+  if (list->fl_files != NULL)
+    {
+      memcpy(files, list->fl_files,
+             list->fl_rows * sizeof(FAR struct file *));
+    }
 
   tmp = list->fl_files;
   list->fl_files = files;
@@ -160,7 +163,10 @@ static int files_extend(FAR struct filelist *list, size_t 
row)
 
   spin_unlock_irqrestore(&list->fl_lock, flags);
 
-  kmm_free(tmp);
+  if (tmp != NULL)
+    {
+      kmm_free(tmp);
+    }
 
   return OK;
 }

Reply via email to