From d63034994ed1e72ea0192c6b17d3f3d63c8b6fb0 Mon Sep 17 00:00:00 2001 From: chao an Date: Tue, 14 Nov 2023 23:58:25 +0800 Subject: [PATCH] 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 --- 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; }