From 3e3e9aadf51f60e3931a670cfe08cdef7668ace6 Mon Sep 17 00:00:00 2001 From: Ming Liu Date: Sat, 24 Aug 2024 13:08:50 +0200 Subject: [PATCH] tmpfiles.c: prevent nftw follow symbolic links 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 Signed-off-by: Ming Liu --- src/tmpfiles.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tmpfiles.c b/src/tmpfiles.c index 15b463c8..671d6838 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -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);