From 112cfb181453e38d3ef4a74fba23abbb53392002 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Fri, 31 Jan 2014 15:35:04 -0800 Subject: shared: include root when canonicalizing conf paths The conf_files_list family accepts an alternate root path to prefix all directories in the list but path_strv_canonicalize_uniq doesn't use it. This results in the suspicious behavior of resolving directory symlinks based on the contents of / instead of the alternate root. This adds a prefix argument to path_strv_canonicalize which will now prepend the prefix, if given, to every path in the list. To avoid answering what a relative path means when called with a root prefix path_strv_canonicalize is now path_strv_canonicalize_absolute and only considers absolute paths. Fortunately all users of already call path_strv_canonicalize with a list of absolute paths. --- src/shared/path-util.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/shared/path-util.c') diff --git a/src/shared/path-util.c b/src/shared/path-util.c index fc42a704b7..bdc54a9aa5 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -153,7 +153,7 @@ char **path_strv_make_absolute_cwd(char **l) { return l; } -char **path_strv_canonicalize(char **l) { +char **path_strv_canonicalize_absolute(char **l, const char *prefix) { char **s; unsigned k = 0; bool enomem = false; @@ -168,13 +168,21 @@ char **path_strv_canonicalize(char **l) { STRV_FOREACH(s, l) { char *t, *u; - t = path_make_absolute_cwd(*s); - free(*s); - *s = NULL; - - if (!t) { - enomem = true; + if (!path_is_absolute(*s)) continue; + + if (prefix) { + t = strappend(prefix, *s); + free(*s); + *s = NULL; + + if (!t) { + enomem = true; + continue; + } + } else { + t = *s; + *s = NULL; } errno = 0; @@ -184,7 +192,7 @@ char **path_strv_canonicalize(char **l) { u = t; else { free(t); - if (errno == ENOMEM || !errno) + if (errno == ENOMEM || errno == 0) enomem = true; continue; @@ -203,11 +211,12 @@ char **path_strv_canonicalize(char **l) { return l; } -char **path_strv_canonicalize_uniq(char **l) { +char **path_strv_canonicalize_absolute_uniq(char **l, const char *prefix) { + if (strv_isempty(l)) return l; - if (!path_strv_canonicalize(l)) + if (!path_strv_canonicalize_absolute(l, prefix)) return NULL; return strv_uniq(l); -- cgit v1.2.3-54-g00ecf