From: Lennart Poettering Date: Wed, 17 Jan 2018 10:56:52 +0000 (+0100) Subject: fs-util: extra safety checks on chase_symlinks() root parameter X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=d569509362723ee91d86feb0f139f2e874cce9d9;p=elogind.git fs-util: extra safety checks on chase_symlinks() root parameter Let's handle root="" and root="/" safely. --- 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)