fs/rename: fix use after free issue about rename

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2023-10-12 21:15:32 +08:00 committed by Xiang Xiao
parent 968e89303f
commit dcc006035d

View File

@ -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;