From 5bf6ea0c20df83575ed94d03bf43598ca961f6e4 Mon Sep 17 00:00:00 2001 From: Yanfeng Liu Date: Tue, 12 Mar 2024 16:26:17 +0800 Subject: [PATCH] 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 --- fs/mount/fs_mount.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c index 83396035e9..2bbef28958 100644 --- a/fs/mount/fs_mount.c +++ b/fs/mount/fs_mount.c @@ -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 */