Skip to content

Commit

Permalink
fix: don't follow symlinks when removing junk files (#1638)
Browse files Browse the repository at this point in the history
This prevents accidentally following a symlink that points outside of
the torrent's folder and crawling the rest of the drive for junk files
to remove.

This also prevents symlinks that point to a folder from being treated as
real directories, which would cause them to be removed even if the folder
they point to is not actually empty.

Both issues are especially bad when combined: a symlink to / inside the
torrent folder caused transmission to crawl the entire drive and delete
every single folder symlink it could find. Oops.
  • Loading branch information
Narthorn committed Jan 18, 2022
1 parent 0166b6e commit 8fdf729
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libtransmission/torrent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ static void removeEmptyFoldersAndJunkFiles(char const* folder)
auto const filename = tr_strvPath(folder, name);

auto info = tr_sys_path_info{};
if (tr_sys_path_get_info(filename.c_str(), 0, &info, nullptr) && info.type == TR_SYS_PATH_IS_DIRECTORY)
if (tr_sys_path_get_info(filename.c_str(), TR_SYS_PATH_NO_FOLLOW, &info, nullptr) && info.type == TR_SYS_PATH_IS_DIRECTORY)
{
removeEmptyFoldersAndJunkFiles(filename.c_str());
}
Expand Down

0 comments on commit 8fdf729

Please sign in to comment.