btrfs_scan_one_dir: avoid use-after-free on error path

If we iterate the "goto again" loop, we've called "closedir(dirp)",
yet at the top of the loop, upon malloc failure we "goto fail",
where we test dirp and if non-NULL, call closedir(dirp) again.
* utils.c (btrfs_scan_one_dir): Clear "dirp" after closedir to avoid
use-after-free upon failed fullpath = malloc(...

Signed-off-by: Jim Meyering <meyering@redhat.com>
This commit is contained in:
Jim Meyering 2012-04-11 16:42:50 +02:00 committed by Hugo Mills
parent eda76e4629
commit 0195702a09

View File

@ -1021,6 +1021,7 @@ again:
list);
list_del(&pending->list);
closedir(dirp);
dirp = NULL;
goto again;
}
ret = 0;