From a91d143944882f701226ee167abb87a88eb46a30 Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Fri, 1 Apr 2022 12:18:45 +0800 Subject: [PATCH] fs/unionfs: add sanity check for parameter if relpath is NULL, it will cause system crash: unionfs_opendir with relpath NULL -> unionfs_tryopendir -> unionfs_offsetpath -> strncmp(prefix, relpath, pfxlen Signed-off-by: Jiuzhu Dong --- fs/unionfs/fs_unionfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/unionfs/fs_unionfs.c b/fs/unionfs/fs_unionfs.c index 704d916822..36dfcf3030 100644 --- a/fs/unionfs/fs_unionfs.c +++ b/fs/unionfs/fs_unionfs.c @@ -1421,6 +1421,11 @@ static int unionfs_opendir(FAR struct inode *mountpt, finfo("relpath: \"%s\"\n", relpath ? relpath : "NULL"); + if (!relpath) + { + return -EINVAL; + } + /* Recover the filesystem data from the struct inode instance */ DEBUGASSERT(mountpt != NULL && mountpt->i_private != NULL); @@ -1441,7 +1446,7 @@ static int unionfs_opendir(FAR struct inode *mountpt, * omit duplicates on file system 1. */ - if (relpath && strlen(relpath) > 0) + if (strlen(relpath) > 0) { fu->fu_relpath = strdup(relpath); if (!fu->fu_relpath)