This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 3d023ecccc6eeadf1b90d0afc27e87ceb7c0cf3c Author: zhengyu16 <[email protected]> AuthorDate: Thu Nov 12 13:08:43 2026 +0800 fs/vfs: reject an empty symlink target symlink() accepts an empty path1 and creates a link to "", which POSIX rejects with ENOENT. It also takes any inode_find() failure for path2 as "path2 does not exist" and goes on to reserve a new node there. Return ENOENT for an empty path1 or path2, and only create the link when the lookup of path2 failed with -ENOENT. Signed-off-by: zhengyu16 <[email protected]> Signed-off-by: jingfei <[email protected]> --- fs/vfs/fs_symlink.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/vfs/fs_symlink.c b/fs/vfs/fs_symlink.c index 5ced61110e0..2e8bcabac69 100644 --- a/fs/vfs/fs_symlink.c +++ b/fs/vfs/fs_symlink.c @@ -83,12 +83,18 @@ int symlink(FAR const char *path1, FAR const char *path2) FAR struct inode *inode = NULL; int ret; - if (path1 == NULL) + if (path1 == NULL || path2 == NULL) { ret = -EINVAL; goto errout; } + if (*path1 == '\0' || *path2 == '\0') + { + ret = -ENOENT; + goto errout; + } + /* Check that no inode exists at the 'path2' and that the path up to * 'path2' does not lie on a mounted volume. */ @@ -139,6 +145,13 @@ int symlink(FAR const char *path1, FAR const char *path2) } } + /* Only a missing path2 may be created; any other error stands */ + + else if (ret != -ENOENT) + { + goto errout_with_search; + } + /* No inode exists that contains this path. Create a new inode in the * pseudo-filesystem at this location. */
