mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
nshlib/nsh_fscmds.c: Allocate a PATH_MAX sized buffer for unlink_recursive
This fixes heap corruption when deleting a folder containing other folders
or files. The issue appeared at commit 131d50ae9d, which removed the
stack-based temporary buffer.
unlink_recursive requires that the path is provided in PATH_MAX sized
buffer. It concatenates sub-folder or file names to the same buffer.
nsh_getfullpath just allocates a buffer using strdup, so there is no room
for concatenating more data to it.
To keep the stack usage smaller, instead of reverting the breaking commit,
allocate the temporary buffer with lib_get_pathbuffer instead.
Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
This commit is contained in:
parent
3f6fc4b4f7
commit
c3247ecc6c
1 changed files with 4 additions and 1 deletions
|
|
@ -2233,7 +2233,10 @@ int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
|||
{
|
||||
if (recursive)
|
||||
{
|
||||
ret = unlink_recursive(fullpath, &stat);
|
||||
FAR char *buf = lib_get_pathbuffer();
|
||||
strlcpy(buf, fullpath, PATH_MAX);
|
||||
ret = unlink_recursive(buf, &stat);
|
||||
lib_put_pathbuffer(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue