Skip to content

Commit

Permalink
tmpfiles.c: prevent nftw follow symbolic links
Browse files Browse the repository at this point in the history
When dealing with "L+" and "R", the function call 'nftw' should not
follow symbolic links, otherwise, it would also delete the targets
which is wrong.

For instance, if there is already a symbolic link:
```
/path/to/the/link -> /path/to/some/folder
```

if we set the following in a tmpfile conf:

```
L+ /path/to/the/link -    -    -     - /path/to/the/target
```

the result would be /path/to/some/folder also get deleted, which it
should not.

it could be even worse, when the symbolic link already is pointing to:
/path/to/the/target, the whole /path/to/the/target would be deleted on
next system boot.

Signed-off-by: Mathias Thore <[email protected]>
Signed-off-by: Ming Liu <[email protected]>
  • Loading branch information
liuming50 committed Aug 24, 2024
1 parent dc873c6 commit 3e3e9aa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/tmpfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static int rmrf(const char *path)
if (!fisdir(path))
return 0;

nftw(path, do_delete, 20, FTW_DEPTH);
nftw(path, do_delete, 20, FTW_DEPTH | FTW_PHYS);
if (remove(path) && errno != ENOENT)
warn("Failed removing path %s", path);

Expand Down

0 comments on commit 3e3e9aa

Please sign in to comment.