fs/mount: harden nx_mount logic

This adds variables initialization and empty device path checks to
harden logic of nx_mount.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
This commit is contained in:
Yanfeng Liu 2024-03-12 16:26:17 +08:00 committed by Xiang Xiao
parent 813f67f93b
commit 5bf6ea0c20

View File

@ -279,12 +279,12 @@ int nx_mount(FAR const char *source, FAR const char *target,
{
#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) || defined(NODFS_SUPPORT)
FAR struct inode *drvr_inode = NULL;
FAR struct inode *mountpt_inode;
FAR struct inode *mountpt_inode = NULL;
FAR const struct mountpt_operations *mops = NULL;
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
struct inode_search_s desc;
#endif
void *fshandle;
void *fshandle = NULL;
int ret;
/* Verify required pointer arguments */
@ -293,7 +293,7 @@ int nx_mount(FAR const char *source, FAR const char *target,
/* Find the specified filesystem. Try the block driver filesystems first */
if (source != NULL &&
if (source != NULL && source[0] != '\0' &&
find_blockdriver(source, mountflags, &drvr_inode) >= 0)
{
/* Find the block based file system */
@ -310,7 +310,7 @@ int nx_mount(FAR const char *source, FAR const char *target,
goto errout_with_inode;
}
}
else if (source != NULL &&
else if (source != NULL && source[0] != '\0' &&
(ret = find_mtddriver(source, &drvr_inode)) >= 0)
{
/* Find the MTD based file system */
@ -331,6 +331,7 @@ int nx_mount(FAR const char *source, FAR const char *target,
#ifdef NODFS_SUPPORT
if ((mops = mount_findfs(g_nonbdfsmap, filesystemtype)) != NULL)
{
finfo("found %s\n", filesystemtype);
}
else
#endif /* NODFS_SUPPORT */