From 382a5078a6d479c6d3f28f1bc3ef3340311fd8f8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 Jan 2018 12:00:40 +0100 Subject: [PATCH] fs-util: refuse taking a relative path to chase if "root" is specified and CHASE_PREFIX_ROOT is set If we take a relative path we first make it absolute, based on the current working directory. But if CHASE_PREFIX_ROOT is passe we are supposed to make the path absolute taking the specified root path into account, but that makes no sense if we talk about the current working directory as that is relative to the host's root in any case. Hence, let's refuse this politely. --- src/basic/fs-util.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index f0df79d8ff..cb56e03d15 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -673,8 +673,14 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, if (r < 0) return r; - if (flags & CHASE_PREFIX_ROOT) + if (flags & CHASE_PREFIX_ROOT) { + + /* We don't support relative paths in combination with a root directory */ + if (!path_is_absolute(path)) + return -EINVAL; + path = prefix_roota(root, path); + } } r = path_make_absolute_cwd(path, &buffer);