summaryrefslogtreecommitdiff
path: root/src/portable
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-08-22 11:38:58 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2022-08-22 19:15:29 +0100
commit8e7e4a730ba40bbc46c9d1e84207fd35781ca05a (patch)
treed3afeaddba38bf96f3df5a08fa7f40aba7a8d2eb /src/portable
parent8ef6106de4ebe633db76deccd257800b5aa8f177 (diff)
downloadsystemd-8e7e4a730ba40bbc46c9d1e84207fd35781ca05a.tar.gz
tree-wide: use path_join() instead of prefix_roota() in various cases
prefix_roota() is something we should stop using. It is bad for three reasons: 1. As it names suggests it's supposed to be used when working relative to some root directory, but given it doesn't follow symlinks (and instead just stupidly joins paths) it is not a good choice for that. 2. More often than not it is currently used with inputs under control of the user, and that is icky given it typically allocates memory on the stack. 3. It's a redundant interface, where chase_symlinks() and path_join() already exist as better, safer interfaces. Hence, let's start moving things from prefix_roota() to path_join() for the cases where that's appropriate.
Diffstat (limited to 'src/portable')
-rw-r--r--src/portable/portable.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/portable/portable.c b/src/portable/portable.c
index c6e74e9c27..256362355c 100644
--- a/src/portable/portable.c
+++ b/src/portable/portable.c
@@ -873,6 +873,8 @@ static int portable_changes_add_with_prefix(
const char *path,
const char *source) {
+ _cleanup_free_ char *path_buf = NULL, *source_buf = NULL;
+
assert(path);
assert(!changes == !n_changes);
@@ -880,10 +882,19 @@ static int portable_changes_add_with_prefix(
return 0;
if (prefix) {
- path = prefix_roota(prefix, path);
+ path_buf = path_join(prefix, path);
+ if (!path_buf)
+ return -ENOMEM;
+
+ path = path_buf;
+
+ if (source) {
+ source_buf = path_join(prefix, source);
+ if (!source_buf)
+ return -ENOMEM;
- if (source)
- source = prefix_roota(prefix, source);
+ source = source_buf;
+ }
}
return portable_changes_add(changes, n_changes, type_or_errno, path, source);
@@ -1098,7 +1109,8 @@ static int attach_unit_file(
_cleanup_(unlink_and_freep) char *chroot_dropin = NULL, *profile_dropin = NULL;
_cleanup_(rmdir_and_freep) char *dropin_dir = NULL;
- const char *where, *path;
+ _cleanup_free_ char *path = NULL;
+ const char *where;
int r;
assert(paths);
@@ -1115,7 +1127,10 @@ static int attach_unit_file(
} else
(void) portable_changes_add(changes, n_changes, PORTABLE_MKDIR, where, NULL);
- path = prefix_roota(where, m->name);
+ path = path_join(where, m->name);
+ if (!path)
+ return -ENOMEM;
+
dropin_dir = strjoin(path, ".d");
if (!dropin_dir)
return -ENOMEM;