daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
da2bf9
From 81b967279f6e23474b1e7a0ea9b4ecf9405f87bb Mon Sep 17 00:00:00 2001
da2bf9
From: Masahiro Matsuya <mmatsuya@redhat.com>
da2bf9
Date: Wed, 31 Mar 2021 11:44:24 +0900
da2bf9
Subject: [PATCH] tmpfiles: use a entry in hashmap as ItemArray in
da2bf9
 read_config_file()
da2bf9
da2bf9
[zjs: squash commits and use size_t as appropriate.
da2bf9
da2bf9
Bug seems to have been introduced in 811a15877825da9e53f9a2a8603da34589af6bbb.
da2bf9
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1944468.]
da2bf9
da2bf9
(cherry picked from commit bec890e3cd6dac249cb12ce9430fdb78b6cf546b)
da2bf9
da2bf9
Resolves: #1944468
da2bf9
---
da2bf9
 src/tmpfiles/tmpfiles.c | 47 +++++++++++++++++++++++------------------
da2bf9
 1 file changed, 26 insertions(+), 21 deletions(-)
da2bf9
da2bf9
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
da2bf9
index 927de35f32..1aeeed0d2e 100644
da2bf9
--- a/src/tmpfiles/tmpfiles.c
da2bf9
+++ b/src/tmpfiles/tmpfiles.c
da2bf9
@@ -2646,7 +2646,7 @@ static int read_config_file(char **config_dirs, const char *fn, bool ignore_enoe
da2bf9
         char line[LINE_MAX];
da2bf9
         Iterator iterator;
da2bf9
         unsigned v = 0;
da2bf9
-        Item *i;
da2bf9
+        ItemArray *ia;
da2bf9
         int r = 0;
da2bf9
 
da2bf9
         assert(fn);
da2bf9
@@ -2692,32 +2692,37 @@ static int read_config_file(char **config_dirs, const char *fn, bool ignore_enoe
da2bf9
         }
da2bf9
 
da2bf9
         /* we have to determine age parameter for each entry of type X */
da2bf9
-        ORDERED_HASHMAP_FOREACH(i, globs, iterator) {
da2bf9
-                Iterator iter;
da2bf9
-                Item *j, *candidate_item = NULL;
da2bf9
+        ORDERED_HASHMAP_FOREACH(ia, globs, iterator)
da2bf9
+                for (size_t ni = 0; ni < ia->count; ni++) {
da2bf9
+                        Iterator iter;
da2bf9
+                        ItemArray *ja;
da2bf9
+                        Item *i = ia->items + ni, *candidate_item = NULL;
da2bf9
 
da2bf9
-                if (i->type != IGNORE_DIRECTORY_PATH)
da2bf9
-                        continue;
da2bf9
-
da2bf9
-                ORDERED_HASHMAP_FOREACH(j, items, iter) {
da2bf9
-                        if (!IN_SET(j->type, CREATE_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA))
da2bf9
+                        if (i->type != IGNORE_DIRECTORY_PATH)
da2bf9
                                 continue;
da2bf9
 
da2bf9
-                        if (path_equal(j->path, i->path)) {
da2bf9
-                                candidate_item = j;
da2bf9
-                                break;
da2bf9
-                        }
da2bf9
+                        ORDERED_HASHMAP_FOREACH(ja, items, iter)
da2bf9
+                                for (size_t nj = 0; nj < ja->count; nj++) {
da2bf9
+                                        Item *j = ja->items + nj;
da2bf9
 
da2bf9
-                        if ((!candidate_item && path_startswith(i->path, j->path)) ||
da2bf9
-                            (candidate_item && path_startswith(j->path, candidate_item->path) && (fnmatch(i->path, j->path, FNM_PATHNAME | FNM_PERIOD) == 0)))
da2bf9
-                                candidate_item = j;
da2bf9
-                }
da2bf9
+                                        if (!IN_SET(j->type, CREATE_DIRECTORY, TRUNCATE_DIRECTORY, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA))
da2bf9
+                                                continue;
da2bf9
 
da2bf9
-                if (candidate_item && candidate_item->age_set) {
da2bf9
-                        i->age = candidate_item->age;
da2bf9
-                        i->age_set = true;
da2bf9
+                                        if (path_equal(j->path, i->path)) {
da2bf9
+                                                candidate_item = j;
da2bf9
+                                                break;
da2bf9
+                                        }
da2bf9
+
da2bf9
+                                        if ((!candidate_item && path_startswith(i->path, j->path)) ||
da2bf9
+                                            (candidate_item && path_startswith(j->path, candidate_item->path) && (fnmatch(i->path, j->path, FNM_PATHNAME | FNM_PERIOD) == 0)))
da2bf9
+                                                candidate_item = j;
da2bf9
+                                }
da2bf9
+
da2bf9
+                        if (candidate_item && candidate_item->age_set) {
da2bf9
+                                i->age = candidate_item->age;
da2bf9
+                                i->age_set = true;
da2bf9
+                        }
da2bf9
                 }
da2bf9
-        }
da2bf9
 
da2bf9
         if (ferror(f)) {
da2bf9
                 log_error_errno(errno, "Failed to read from file %s: %m", fn);