RT-Thread Version
RT-Thread master (f12485a60e), source version 5.3.0.
Hardware Type/Architectures
Not hardware-specific. This is a source-level cleanup issue in DFS POSIX compatibility code: components/dfs/dfs_v2/src/dfs_posix.c
Develop Toolchain
Other
Describe the bug
In components/dfs/dfs_v2/src/dfs_posix.c, utimensat() allocates link_fn before validating __path and before several early-return checks:
char *link_fn = (char *)rt_malloc(DFS_PATH_MAX);
int err;
if (__path == NULL)
{
return -EFAULT;
}
If __path == NULL, the function returns immediately and leaks link_fn.
There are additional early-return paths before the final rt_free(link_fn), for example:
if (stat(__path, &buffer) < 0)
{
return -ENOENT;
}
and:
d = fd_get(__fd);
if (!d || !d->vnode)
{
return -EBADF;
}
fullpath = dfs_dentry_full_path(d->dentry);
if (!fullpath)
{
rt_set_errno(-ENOMEM);
return -1;
}
The function only frees link_fn on later paths:
ret = dfs_file_setattr(fullpath, &attr);
rt_free(link_fn);
return ret;
Steps to reproduce the behavior
Any caller that reaches an early error path after link_fn is allocated can trigger the leak. For example:
- Call
utimensat() with __path == NULL.
link_fn is allocated with rt_malloc(DFS_PATH_MAX).
- The function returns
-EFAULT.
link_fn is not freed.
Other examples include paths where stat(__path, &buffer) fails, fd_get(__fd) fails, or dfs_dentry_full_path() fails.
Other additional context
No response
RT-Thread Version
RT-Thread master (
f12485a60e), source version5.3.0.Hardware Type/Architectures
Not hardware-specific. This is a source-level cleanup issue in DFS POSIX compatibility code:
components/dfs/dfs_v2/src/dfs_posix.cDevelop Toolchain
Other
Describe the bug
In
components/dfs/dfs_v2/src/dfs_posix.c,utimensat()allocateslink_fnbefore validating__pathand before several early-return checks:If
__path == NULL, the function returns immediately and leakslink_fn.There are additional early-return paths before the final
rt_free(link_fn), for example:and:
The function only frees
link_fnon later paths:Steps to reproduce the behavior
Any caller that reaches an early error path after
link_fnis allocated can trigger the leak. For example:utimensat()with__path == NULL.link_fnis allocated withrt_malloc(DFS_PATH_MAX).-EFAULT.link_fnis not freed.Other examples include paths where
stat(__path, &buffer)fails,fd_get(__fd)fails, ordfs_dentry_full_path()fails.Other additional context
No response