fs/rename: fix use after free issue about rename
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
968e89303f
commit
dcc006035d
@ -348,14 +348,6 @@ next_subdir:
|
||||
{
|
||||
FAR char *subdirname;
|
||||
|
||||
/* Free memory may be allocated in previous loop */
|
||||
|
||||
if (subdir != NULL)
|
||||
{
|
||||
lib_free(subdir);
|
||||
subdir = NULL;
|
||||
}
|
||||
|
||||
/* Yes.. In this case, the target of the rename must be a
|
||||
* subdirectory of newinode, not the newinode itself. For
|
||||
* example: mv b a/ must move b to a/b.
|
||||
@ -371,8 +363,19 @@ next_subdir:
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Save subdir to free memory may be allocated in
|
||||
* previous loop.
|
||||
*/
|
||||
|
||||
FAR void *tmp = subdir;
|
||||
|
||||
ret = asprintf(&subdir, "%s/%s", newrelpath,
|
||||
subdirname);
|
||||
if (tmp != NULL)
|
||||
{
|
||||
lib_free(tmp);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
subdir = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user