diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-04-05 20:25:14 +0800 |
---|---|---|
committer | Daniel Kirchner <daniel@ekpyron.org> | 2018-04-12 00:52:22 +0800 |
commit | c15cb6cc7ac68e539dd3969e614be52e9a943ec7 (patch) | |
tree | cdea8bee96837cffd048c69407a8cdd2e65e4858 /libdevcore | |
parent | f39f36f2c7f38ecc8c171447de4c65c8cb968640 (diff) | |
download | dexon-solidity-c15cb6cc7ac68e539dd3969e614be52e9a943ec7.tar.gz dexon-solidity-c15cb6cc7ac68e539dd3969e614be52e9a943ec7.tar.zst dexon-solidity-c15cb6cc7ac68e539dd3969e614be52e9a943ec7.zip |
Prevent information about file existence outside the allowed paths to leak by mimicing boost::filesystem::weakly_canonical.
Diffstat (limited to 'libdevcore')
-rw-r--r-- | libdevcore/CommonIO.cpp | 20 | ||||
-rw-r--r-- | libdevcore/CommonIO.h | 5 |
2 files changed, 25 insertions, 0 deletions
diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 6526baf9..0063a8d4 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -167,3 +167,23 @@ int dev::readStandardInputChar() DisableConsoleBuffering disableConsoleBuffering; return cin.get(); } + +boost::filesystem::path dev::weaklyCanonicalFilesystemPath(boost::filesystem::path const &_path) +{ + if (boost::filesystem::exists(_path)) + return boost::filesystem::canonical(_path); + else + { + boost::filesystem::path head(_path); + boost::filesystem::path tail; + for (auto it = --_path.end(); !head.empty(); --it) + { + if (boost::filesystem::exists(head)) + break; + tail = (*it) / tail; + head.remove_filename(); + } + head = boost::filesystem::canonical(head); + return head / tail; + } +} diff --git a/libdevcore/CommonIO.h b/libdevcore/CommonIO.h index 3ecdb4c3..9ba68e74 100644 --- a/libdevcore/CommonIO.h +++ b/libdevcore/CommonIO.h @@ -25,6 +25,7 @@ #include <sstream> #include <string> +#include <boost/filesystem.hpp> #include "Common.h" namespace dev @@ -57,4 +58,8 @@ std::string toString(_T const& _t) return o.str(); } +/// Partial implementation of boost::filesystem::weakly_canonical (available in boost>=1.60). +/// Should be replaced by the boost implementation as soon as support for boost<1.60 can be dropped. +boost::filesystem::path weaklyCanonicalFilesystemPath(boost::filesystem::path const &_path); + } |