From 8a18f22b878b86fff8e2f49a99397320180d4b22 Mon Sep 17 00:00:00 2001 From: Anthony Broad-Crawford Date: Fri, 16 Mar 2018 10:52:04 -0500 Subject: Support for error on non-existant or irregular files with command line option to ignore --- solc/CommandLineInterface.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index d3d234c3..8f81e799 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -116,6 +116,7 @@ static string const g_strStandardJSON = "standard-json"; static string const g_strStrictAssembly = "strict-assembly"; static string const g_strPrettyJson = "pretty-json"; static string const g_strVersion = "version"; +static string const g_strIgnoreMissingFiles = "ignore-missing"; static string const g_argAbi = g_strAbi; static string const g_argPrettyJson = g_strPrettyJson; @@ -152,6 +153,7 @@ static string const g_argStandardJSON = g_strStandardJSON; static string const g_argStrictAssembly = g_strStrictAssembly; static string const g_argVersion = g_strVersion; static string const g_stdinFileName = g_stdinFileNameStr; +static string const g_argIgnoreMissingFiles = g_strIgnoreMissingFiles; /// Possible arguments to for --combined-json static set const g_combinedJsonArgs @@ -398,8 +400,9 @@ void CommandLineInterface::handleGasEstimation(string const& _contract) } } -void CommandLineInterface::readInputFilesAndConfigureRemappings() +bool CommandLineInterface::readInputFilesAndConfigureRemappings() { + bool ignoreMissing = m_args.count(g_argIgnoreMissingFiles); bool addStdin = false; if (!m_args.count(g_argInputFile)) addStdin = true; @@ -416,13 +419,27 @@ void CommandLineInterface::readInputFilesAndConfigureRemappings() auto infile = boost::filesystem::path(path); if (!boost::filesystem::exists(infile)) { - cerr << "Skipping non-existent input file \"" << infile << "\"" << endl; + if (!ignoreMissing) + { + cerr << "\"" << infile << "\" is not found" << endl; + return false; + } + else + cerr << "\"" << infile << "\" is not found. Skipping." << endl; + continue; } if (!boost::filesystem::is_regular_file(infile)) { - cerr << "\"" << infile << "\" is not a valid file. Skipping" << endl; + if (!ignoreMissing) + { + cerr << "\"" << infile << "\" is not a valid file" << endl; + return false; + } + else + cerr << "\"" << infile << "\" is not a valid file. Skipping." << endl; + continue; } @@ -433,6 +450,8 @@ void CommandLineInterface::readInputFilesAndConfigureRemappings() } if (addStdin) m_sourceCodes[g_stdinFileName] = dev::readStandardInput(); + + return true; } bool CommandLineInterface::parseLibraryOption(string const& _input) @@ -599,7 +618,8 @@ Allowed options)", g_argAllowPaths.c_str(), po::value()->value_name("path(s)"), "Allow a given path for imports. A list of paths can be supplied by separating them with a comma." - ); + ) + (g_argIgnoreMissingFiles.c_str(), "Ignore missing files."); po::options_description outputComponents("Output Components"); outputComponents.add_options() (g_argAst.c_str(), "AST of all source files.") @@ -741,7 +761,8 @@ bool CommandLineInterface::processInput() return true; } - readInputFilesAndConfigureRemappings(); + if (!readInputFilesAndConfigureRemappings()) + return false; if (m_args.count(g_argLibraries)) for (string const& library: m_args[g_argLibraries].as>()) -- cgit v1.2.3 From f39f36f2c7f38ecc8c171447de4c65c8cb968640 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Tue, 3 Oct 2017 18:48:53 +0100 Subject: Fix file missing error message on imports. Trying to convert an import path into a Boost canonical path causes boost to throw an exception if the given file does not exist. Thus, instead of geting to the 'File not found' error, we instead got into the cath-all handler for 'Unknown exception in read callback'. This change rearranges the file checks to happen before we create a canonical Boost path. It also drive-by removes the unnecessary 'else' block, as the body of the if is a guard-like return block. --- solc/CommandLineInterface.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 8f81e799..93203de6 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -700,7 +700,13 @@ bool CommandLineInterface::processInput() try { auto path = boost::filesystem::path(_path); + if (!boost::filesystem::exists(path)) + return ReadCallback::Result{false, "File not found."}; + auto canonicalPath = boost::filesystem::canonical(path); + if (!boost::filesystem::is_regular_file(canonicalPath)) + return ReadCallback::Result{false, "Not a valid file."}; + bool isAllowed = false; for (auto const& allowedDir: m_allowedDirectories) { @@ -716,16 +722,10 @@ bool CommandLineInterface::processInput() } if (!isAllowed) return ReadCallback::Result{false, "File outside of allowed directories."}; - else if (!boost::filesystem::exists(path)) - return ReadCallback::Result{false, "File not found."}; - else if (!boost::filesystem::is_regular_file(canonicalPath)) - return ReadCallback::Result{false, "Not a valid file."}; - else - { - auto contents = dev::readFileAsString(canonicalPath.string()); - m_sourceCodes[path.string()] = contents; - return ReadCallback::Result{true, contents}; - } + + auto contents = dev::readFileAsString(canonicalPath.string()); + m_sourceCodes[path.string()] = contents; + return ReadCallback::Result{true, contents}; } catch (Exception const& _exception) { -- cgit v1.2.3 From c15cb6cc7ac68e539dd3969e614be52e9a943ec7 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 5 Apr 2018 14:25:14 +0200 Subject: Prevent information about file existence outside the allowed paths to leak by mimicing boost::filesystem::weakly_canonical. --- solc/CommandLineInterface.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 93203de6..4da394b2 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -700,13 +700,7 @@ bool CommandLineInterface::processInput() try { auto path = boost::filesystem::path(_path); - if (!boost::filesystem::exists(path)) - return ReadCallback::Result{false, "File not found."}; - - auto canonicalPath = boost::filesystem::canonical(path); - if (!boost::filesystem::is_regular_file(canonicalPath)) - return ReadCallback::Result{false, "Not a valid file."}; - + auto canonicalPath = weaklyCanonicalFilesystemPath(path); bool isAllowed = false; for (auto const& allowedDir: m_allowedDirectories) { @@ -723,6 +717,12 @@ bool CommandLineInterface::processInput() if (!isAllowed) return ReadCallback::Result{false, "File outside of allowed directories."}; + if (!boost::filesystem::exists(canonicalPath)) + return ReadCallback::Result{false, "File not found."}; + + if (!boost::filesystem::is_regular_file(canonicalPath)) + return ReadCallback::Result{false, "Not a valid file."}; + auto contents = dev::readFileAsString(canonicalPath.string()); m_sourceCodes[path.string()] = contents; return ReadCallback::Result{true, contents}; -- cgit v1.2.3 From 576964bd016e265db9720946d626b8af9b4e4b14 Mon Sep 17 00:00:00 2001 From: Li Xuanji Date: Wed, 11 Apr 2018 19:20:39 +0800 Subject: Mark --formal as deprecated in CLI options --- solc/CommandLineInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 8f81e799..fc03d497 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -636,7 +636,7 @@ Allowed options)", (g_argNatspecUser.c_str(), "Natspec user documentation of all contracts.") (g_argNatspecDev.c_str(), "Natspec developer documentation of all contracts.") (g_argMetadata.c_str(), "Combined Metadata JSON whose Swarm hash is stored on-chain.") - (g_argFormal.c_str(), "Translated source suitable for formal analysis."); + (g_argFormal.c_str(), "Translated source suitable for formal analysis. (Deprecated)"); desc.add(outputComponents); po::options_description allOptions = desc; -- cgit v1.2.3