81bf92596f
- Added patches to fix CVE-2021-3997 (bsc#1194178) 5000-shared-rm_rf-refactor-rm_rf_children_inner-to-shorte.patch 5001-shared-rm_rf-refactor-rm_rf-to-shorten-code-a-bit.patch 5002-shared-rm-rf-loop-over-nested-directories-instead-of.patch These patches will be dropped and cherry-picked from upstream once upstream will commit them in their main branch. - Import commit a54f80116ccf105dff11aef5d18dd110ebd3e8ee 30cbebc56f tmpfiles: 'st' may have been used uninitialized 5443654ec0 macro: add new helper RET_NERRNO() 8d90ecc435 rm-rf: optionally fsync() after removing directory tree 591344010d rm-rf: refactor rm_rf_children(), split out body of directory iteration loop 8c7762c4f1 Bump the max number of inodes for /dev to a million (bsc#1192858) dc9476c881 journal: don't remove the flushed flag when journald is stopped 29efc29efd TEST-10: don't attempt to write a byte to the socket 773fb785b6 Bump the max number of inodes for /dev to 128k (bsc#1192858) OBS-URL: https://build.opensuse.org/request/show/945520 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=343
99 lines
3.5 KiB
Diff
99 lines
3.5 KiB
Diff
From 8f608df0305355c9b2ddd7c75926a6bd6247e635 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Date: Tue, 23 Nov 2021 16:56:42 +0100
|
|
Subject: [PATCH 5001/5002] shared/rm_rf: refactor rm_rf() to shorten code a
|
|
bit
|
|
|
|
---
|
|
src/shared/rm-rf.c | 53 ++++++++++++++++++++--------------------------
|
|
1 file changed, 23 insertions(+), 30 deletions(-)
|
|
|
|
diff --git a/src/shared/rm-rf.c b/src/shared/rm-rf.c
|
|
index 7362954116..c7d3b8b7ad 100644
|
|
--- a/src/shared/rm-rf.c
|
|
+++ b/src/shared/rm-rf.c
|
|
@@ -250,7 +250,7 @@ int rm_rf_children(
|
|
}
|
|
|
|
int rm_rf(const char *path, RemoveFlags flags) {
|
|
- int fd, r;
|
|
+ int fd, r, q = 0;
|
|
|
|
assert(path);
|
|
|
|
@@ -282,49 +282,42 @@ int rm_rf(const char *path, RemoveFlags flags) {
|
|
}
|
|
|
|
fd = open(path, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
|
|
- if (fd < 0) {
|
|
+ if (fd >= 0) {
|
|
+ /* We have a dir */
|
|
+ r = rm_rf_children(fd, flags, NULL);
|
|
+
|
|
+ if (FLAGS_SET(flags, REMOVE_ROOT))
|
|
+ q = RET_NERRNO(rmdir(path));
|
|
+ } else {
|
|
if (FLAGS_SET(flags, REMOVE_MISSING_OK) && errno == ENOENT)
|
|
return 0;
|
|
|
|
if (!IN_SET(errno, ENOTDIR, ELOOP))
|
|
return -errno;
|
|
|
|
- if (FLAGS_SET(flags, REMOVE_ONLY_DIRECTORIES))
|
|
+ if (FLAGS_SET(flags, REMOVE_ONLY_DIRECTORIES) || !FLAGS_SET(flags, REMOVE_ROOT))
|
|
return 0;
|
|
|
|
- if (FLAGS_SET(flags, REMOVE_ROOT)) {
|
|
-
|
|
- if (!FLAGS_SET(flags, REMOVE_PHYSICAL)) {
|
|
- struct statfs s;
|
|
-
|
|
- if (statfs(path, &s) < 0)
|
|
- return -errno;
|
|
- if (is_physical_fs(&s))
|
|
- return log_error_errno(SYNTHETIC_ERRNO(EPERM),
|
|
- "Attempted to remove files from a disk file system under \"%s\", refusing.",
|
|
- path);
|
|
- }
|
|
-
|
|
- if (unlink(path) < 0) {
|
|
- if (FLAGS_SET(flags, REMOVE_MISSING_OK) && errno == ENOENT)
|
|
- return 0;
|
|
+ if (!FLAGS_SET(flags, REMOVE_PHYSICAL)) {
|
|
+ struct statfs s;
|
|
|
|
+ if (statfs(path, &s) < 0)
|
|
return -errno;
|
|
- }
|
|
+ if (is_physical_fs(&s))
|
|
+ return log_error_errno(SYNTHETIC_ERRNO(EPERM),
|
|
+ "Attempted to remove files from a disk file system under \"%s\", refusing.",
|
|
+ path);
|
|
}
|
|
|
|
- return 0;
|
|
+ r = 0;
|
|
+ q = RET_NERRNO(unlink(path));
|
|
}
|
|
|
|
- r = rm_rf_children(fd, flags, NULL);
|
|
-
|
|
- if (FLAGS_SET(flags, REMOVE_ROOT) &&
|
|
- rmdir(path) < 0 &&
|
|
- r >= 0 &&
|
|
- (!FLAGS_SET(flags, REMOVE_MISSING_OK) || errno != ENOENT))
|
|
- r = -errno;
|
|
-
|
|
- return r;
|
|
+ if (r < 0)
|
|
+ return r;
|
|
+ if (q < 0 && (q != -ENOENT || !FLAGS_SET(flags, REMOVE_MISSING_OK)))
|
|
+ return q;
|
|
+ return 0;
|
|
}
|
|
|
|
int rm_rf_child(int fd, const char *name, RemoveFlags flags) {
|
|
--
|
|
2.31.1
|
|
|