From da19c07198167946d35be9fdf908bb683da49cfe Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 19 Mar 2023 02:33:29 +0900 Subject: [PATCH] rm-rf: mask file mode with 07777 when passed to chmod() No functional change hopefully, just for safety. --- src/shared/rm-rf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shared/rm-rf.c b/src/shared/rm-rf.c index 1695e1555a2..55858c7ed15 100644 --- a/src/shared/rm-rf.c +++ b/src/shared/rm-rf.c @@ -71,11 +71,11 @@ int unlinkat_harder(int dfd, const char *filename, int unlink_flags, RemoveFlags if (unlinkat(dfd, filename, unlink_flags) < 0) { r = -errno; /* Try to restore the original access mode if this didn't work */ - (void) fchmod(dfd, old_mode); + (void) fchmod(dfd, old_mode & 07777); return r; } - if (FLAGS_SET(remove_flags, REMOVE_CHMOD_RESTORE) && fchmod(dfd, old_mode) < 0) + if (FLAGS_SET(remove_flags, REMOVE_CHMOD_RESTORE) && fchmod(dfd, old_mode & 07777) < 0) return -errno; /* If this worked, we won't reset the old mode by default, since we'll need it for other entries too, @@ -105,11 +105,11 @@ int fstatat_harder(int dfd, if (fstatat(dfd, filename, ret, fstatat_flags) < 0) { r = -errno; - (void) fchmod(dfd, old_mode); + (void) fchmod(dfd, old_mode & 07777); return r; } - if (FLAGS_SET(remove_flags, REMOVE_CHMOD_RESTORE) && fchmod(dfd, old_mode) < 0) + if (FLAGS_SET(remove_flags, REMOVE_CHMOD_RESTORE) && fchmod(dfd, old_mode & 07777) < 0) return -errno; return 0; -- 2.47.3