From c3a34a595636f394845a4c96ece179582035fa2e Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis <acassis@gmail.com> Date: Thu, 19 Jan 2023 12:17:28 -0300 Subject: [PATCH] fs: Avoid accessing filep fields if it is NULL & add DEBUGASSERTs --- fs/inode/fs_files.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index a467747181..570f5f5f6a 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -269,6 +269,9 @@ int files_duplist(FAR struct filelist *plist, FAR struct filelist *clist) int i; int j; + DEBUGASSERT(clist); + DEBUGASSERT(plist); + ret = nxmutex_lock(&plist->fl_lock); if (ret < 0) { @@ -298,7 +301,10 @@ int files_duplist(FAR struct filelist *plist, FAR struct filelist *clist) #endif filep = &plist->fl_files[i][j]; - if (filep->f_inode == NULL || (filep->f_oflags & O_CLOEXEC) != 0) + DEBUGASSERT(filep); + + if (filep && (filep->f_inode == NULL || + (filep->f_oflags & O_CLOEXEC) != 0)) { continue; }