From: Yu Watanabe Date: Sat, 18 Mar 2023 17:33:29 +0000 (+0900) Subject: rm-rf: mask file mode with 07777 when passed to chmod() X-Git-Tag: v254-rc1~860^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=da19c07198167946d35be9fdf908bb683da49cfe;p=thirdparty%2Fsystemd.git rm-rf: mask file mode with 07777 when passed to chmod() No functional change hopefully, just for safety. --- 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;