From 8bf80ae641b834936e8674f7f6f10fdac291b1bf Mon Sep 17 00:00:00 2001 From: Greg Pfeil Date: Wed, 17 Aug 2022 11:44:53 -0600 Subject: [PATCH 1/2] Canonicalize some user-provided paths These paths get displayed to users, so showing the resolved path (e.g., without "../") is clearer. Also, these paths are created if they don't exist. So if you provide something like `-exportdir=doesntexist/../real_path`, Boost will create `doesntexist/` if you create the directories before canonicalizing the path, even though it isn't used. --- src/util/system.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/system.cpp b/src/util/system.cpp index d0b300148..94d345e99 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -318,7 +318,7 @@ const fs::path GetExportDir() fs::path path; LOCK(cs_args); if (mapArgs.count("-exportdir")) { - path = fs::system_complete(mapArgs["-exportdir"]); + path = fs::weakly_canonical(fs::system_complete(mapArgs["-exportdir"])); if (fs::exists(path) && !fs::is_directory(path)) { throw std::runtime_error(strprintf("The -exportdir '%s' already exists and is not a directory", path.string())); } @@ -342,7 +342,7 @@ const fs::path &GetDataDir(bool fNetSpecific) return path; if (mapArgs.count("-datadir")) { - path = fs::system_complete(mapArgs["-datadir"]); + path = fs::weakly_canonical(fs::system_complete(mapArgs["-datadir"])); if (!fs::is_directory(path)) { path = ""; return path; From a5d108868351cc0429d3a3b9475dfb7eb76628a0 Mon Sep 17 00:00:00 2001 From: Greg Pfeil Date: Thu, 25 Aug 2022 09:26:40 -0600 Subject: [PATCH 2/2] Also canonicalize paramsdir. --- src/util/system.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/system.cpp b/src/util/system.cpp index 94d345e99..f737eea98 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -299,7 +299,7 @@ const fs::path &ZC_GetParamsDir() return path; if (mapArgs.count("-paramsdir")) { - path = fs::system_complete(mapArgs["-paramsdir"]); + path = fs::weakly_canonical(fs::system_complete(mapArgs["-paramsdir"])); if (!fs::is_directory(path)) { throw std::runtime_error(strprintf("The -paramsdir '%s' does not exist or is not a directory", path.string())); }