]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rm-rf: mask file mode with 07777 when passed to chmod()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 18 Mar 2023 17:33:29 +0000 (02:33 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 24 Mar 2023 19:50:27 +0000 (04:50 +0900)
No functional change hopefully, just for safety.

src/shared/rm-rf.c

index 1695e1555a299d91994bbb10ac5bc04f1a5abe9a..55858c7ed15f0c187af13812472057537cc5965d 100644 (file)
@@ -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;