From b1bfb848046e457f3cd623286b8cc1a5e5440023 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 Jan 2018 11:56:52 +0100 Subject: [PATCH] fs-util: extra safety checks on chase_symlinks() root parameter Let's handle root="" and root="/" safely. --- src/basic/fs-util.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 068f5660fa..15f9958c05 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -657,6 +657,14 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, * function what to do when encountering a symlink with an absolute path as directory: prefix it by the * specified path. */ + if (original_root) { + if (isempty(original_root)) /* What's this even supposed to mean? */ + return -EINVAL; + + if (path_equal(original_root, "/")) /* A root directory of "/" is identical to none */ + original_root = NULL; + } + if (original_root) { r = path_make_absolute_cwd(original_root, &root); if (r < 0)