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 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-04-01 12:18:45 +08:00 committed by Xiang Xiao
parent e4c9a491c8
commit a91d143944

View file

@ -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)