summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-12-19 23:05:48 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-12-20 09:56:51 +0100
commit082bb1c59bd4300bcdc08488c94109680cfadf57 (patch)
tree5d0acf2bdc803e23c2389751ce676db655e7d648 /src/basic
parentfcfb1f775ed0e9d282607bb118ba788b98952855 (diff)
downloadsystemd-082bb1c59bd4300bcdc08488c94109680cfadf57.tar.gz
tmpfiles: fix crash with NULL in arg_root and other fixes and tests
The function to replacement paths into the configuration file list was borked. Apart from the crash with empty root prefix, it would incorrectly handle the case where root *was* set, and the replacement file was supposed to override an existing file. prefix_root is used instead of path_join because prefix_root removes duplicate slashes (when --root=dir/ is used). A test is added. Fixes #11124.
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/conf-files.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c
index 76750606b4..b70c6e50a8 100644
--- a/src/basic/conf-files.c
+++ b/src/basic/conf-files.c
@@ -201,14 +201,17 @@ int conf_files_insert(char ***strv, const char *root, char **dirs, const char *p
if (c == 0) {
char **dir;
- /* Oh, we found our spot and it already contains something. */
+ /* Oh, there already is an entry with a matching name (the last component). */
+
STRV_FOREACH(dir, dirs) {
+ _cleanup_free_ char *rdir = NULL;
char *p1, *p2;
- p1 = path_startswith((*strv)[i], root);
- if (p1)
- /* Skip "/" in *dir, because p1 is without "/" too */
- p1 = path_startswith(p1, *dir + 1);
+ rdir = prefix_root(root, *dir);
+ if (!rdir)
+ return -ENOMEM;
+
+ p1 = path_startswith((*strv)[i], rdir);
if (p1)
/* Existing entry with higher priority
* or same priority, no need to do anything. */
@@ -217,7 +220,8 @@ int conf_files_insert(char ***strv, const char *root, char **dirs, const char *p
p2 = path_startswith(path, *dir);
if (p2) {
/* Our new entry has higher priority */
- t = path_join(root, path);
+
+ t = prefix_root(root, path);
if (!t)
return log_oom();
@@ -233,7 +237,8 @@ int conf_files_insert(char ***strv, const char *root, char **dirs, const char *p
/* … we are not there yet, let's continue */
}
- t = path_join(root, path);
+ /* The new file has lower priority than all the existing entries */
+ t = prefix_root(root, path);
if (!t)
return -ENOMEM;
@@ -308,7 +313,7 @@ int conf_files_list_with_replacement(
if (r < 0)
return log_error_errno(r, "Failed to extend config file list: %m");
- p = path_join(root, replacement);
+ p = prefix_root(root, replacement);
if (!p)
return log_oom();
}