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 72069679c74e8c243a17ff8e017db42470978c06 Author: zhengyu16 <[email protected]> AuthorDate: Thu Nov 12 13:08:43 2026 +0800 fs/vfs: return EINVAL from rmdir() of "dir/." The path lookup collapses "." segments, so rmdir("dir/.") and rmdir("dir/./") remove dir. POSIX requires EINVAL when the last component of the path is dot. Check the path before the lookup, ignoring trailing slashes. Signed-off-by: zhengyu16 <[email protected]> Signed-off-by: jingfei <[email protected]> --- fs/vfs/fs_rmdir.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/vfs/fs_rmdir.c b/fs/vfs/fs_rmdir.c index 490984fdeea..968b2c25b39 100644 --- a/fs/vfs/fs_rmdir.c +++ b/fs/vfs/fs_rmdir.c @@ -30,6 +30,7 @@ #include <unistd.h> #include <assert.h> #include <errno.h> +#include <string.h> #include <nuttx/fs/fs.h> @@ -62,8 +63,24 @@ int rmdir(FAR const char *pathname) { struct inode_search_s desc; FAR struct inode *inode; + size_t len; int ret; + /* The lookup collapses ".", so reject a last component of "." first */ + + len = pathname != NULL ? strlen(pathname) : 0; + while (len > 1 && pathname[len - 1] == '/') + { + len--; + } + + if ((len == 1 && pathname[0] == '.') || + (len >= 2 && pathname[len - 1] == '.' && pathname[len - 2] == '/')) + { + ret = -EINVAL; + goto errout; + } + /* Get an inode for the directory (or for the mountpoint containing the * directory). inode_find() automatically increments the reference count * on the inode if one is found.
