From d569509362723ee91d86feb0f139f2e874cce9d9 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 32b1fb605..7a05e22ea 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -39,6 +39,7 @@ #include "mkdir.h" #include "parse-util.h" #include "path-util.h" +//#include "process-util.h" #include "stat-util.h" #include "stdio-util.h" #include "string-util.h" @@ -671,6 +672,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) -- 2.30.2