diff options
author | chriseth <chris@ethereum.org> | 2017-04-24 18:28:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-24 18:28:03 +0800 |
commit | a9f4215720ad7185e9a109ea1cf317d539c1b8e5 (patch) | |
tree | a05781e58713c07e4f54012b49254db2c171385c | |
parent | aa441668db9ea5ec68b8988209c3ed7c82659876 (diff) | |
parent | c82a203206ff36be2aea0c1d1ef976ddf085d65a (diff) | |
download | dexon-solidity-a9f4215720ad7185e9a109ea1cf317d539c1b8e5.tar.gz dexon-solidity-a9f4215720ad7185e9a109ea1cf317d539c1b8e5.tar.zst dexon-solidity-a9f4215720ad7185e9a109ea1cf317d539c1b8e5.zip |
Merge pull request #2155 from ethereum/guard-readcallback
Guard ReadFileCallback exceptions
-rw-r--r-- | libsolidity/interface/CompilerStack.h | 3 | ||||
-rw-r--r-- | libsolidity/interface/StandardCompiler.h | 3 | ||||
-rw-r--r-- | solc/CommandLineInterface.cpp | 53 |
3 files changed, 36 insertions, 23 deletions
diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index a34a34bb..d46c99be 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -79,7 +79,8 @@ class CompilerStack: boost::noncopyable { public: /// Creates a new compiler stack. - /// @param _readFile callback to used to read files for import statements. Should return + /// @param _readFile callback to used to read files for import statements. Must return + /// and must not emit exceptions. explicit CompilerStack(ReadFile::Callback const& _readFile = ReadFile::Callback()); /// Sets path remappings in the format "context:prefix=target" diff --git a/libsolidity/interface/StandardCompiler.h b/libsolidity/interface/StandardCompiler.h index 0b714834..dfaf88cd 100644 --- a/libsolidity/interface/StandardCompiler.h +++ b/libsolidity/interface/StandardCompiler.h @@ -38,7 +38,8 @@ class StandardCompiler: boost::noncopyable { public: /// Creates a new StandardCompiler. - /// @param _readFile callback to used to read files for import statements. Should return + /// @param _readFile callback to used to read files for import statements. Must return + /// and must not emit exceptions. StandardCompiler(ReadFile::Callback const& _readFile = ReadFile::Callback()) : m_compilerStack(_readFile), m_readFile(_readFile) { diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 2bfd0bf2..632c400b 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -618,32 +618,43 @@ bool CommandLineInterface::processInput() { ReadFile::Callback fileReader = [this](string const& _path) { - auto path = boost::filesystem::path(_path); - auto canonicalPath = boost::filesystem::canonical(path); - bool isAllowed = false; - for (auto const& allowedDir: m_allowedDirectories) + try { - // If dir is a prefix of boostPath, we are fine. - if ( - std::distance(allowedDir.begin(), allowedDir.end()) <= std::distance(canonicalPath.begin(), canonicalPath.end()) && - std::equal(allowedDir.begin(), allowedDir.end(), canonicalPath.begin()) - ) + auto path = boost::filesystem::path(_path); + auto canonicalPath = boost::filesystem::canonical(path); + bool isAllowed = false; + for (auto const& allowedDir: m_allowedDirectories) { - isAllowed = true; - break; + // If dir is a prefix of boostPath, we are fine. + if ( + std::distance(allowedDir.begin(), allowedDir.end()) <= std::distance(canonicalPath.begin(), canonicalPath.end()) && + std::equal(allowedDir.begin(), allowedDir.end(), canonicalPath.begin()) + ) + { + isAllowed = true; + break; + } + } + if (!isAllowed) + return ReadFile::Result{false, "File outside of allowed directories."}; + else if (!boost::filesystem::exists(path)) + return ReadFile::Result{false, "File not found."}; + else if (!boost::filesystem::is_regular_file(canonicalPath)) + return ReadFile::Result{false, "Not a valid file."}; + else + { + auto contents = dev::contentsString(canonicalPath.string()); + m_sourceCodes[path.string()] = contents; + return ReadFile::Result{true, contents}; } } - if (!isAllowed) - return ReadFile::Result{false, "File outside of allowed directories."}; - else if (!boost::filesystem::exists(path)) - return ReadFile::Result{false, "File not found."}; - else if (!boost::filesystem::is_regular_file(canonicalPath)) - return ReadFile::Result{false, "Not a valid file."}; - else + catch (Exception const& _exception) + { + return ReadFile::Result{false, "Exception in read callback: " + boost::diagnostic_information(_exception)}; + } + catch (...) { - auto contents = dev::contentsString(canonicalPath.string()); - m_sourceCodes[path.string()] = contents; - return ReadFile::Result{true, contents}; + return ReadFile::Result{false, "Unknown exception in read callback."}; } }; |