CommandLineInterface: Fix output directory creation for paths ending with a slash and equivalent but not equal to dot or double dot

This commit is contained in:
Kamil Śliwak 2020-11-14 02:58:13 +01:00
parent f1846b57a2
commit 9f67d26a1a
2 changed files with 10 additions and 6 deletions

View File

@ -27,6 +27,7 @@ Bugfixes:
* SMTChecker: Fix false negative in modifier applied multiple times.
* SMTChecker: Fix internal error in the BMC engine when inherited contract from a different source unit has private state variables.
* SMTChecker: Fix internal error when ``array.push()`` is used as the LHS of an assignment.
* Command Line Interface: Fix write error when the directory passed to ``--output-dir`` ends with a slash.
* SMTChecker: Fix CHC false positives when branches are used inside modifiers.
* Code generator: Fix missing creation dependency tracking for abstract contracts.

View File

@ -730,12 +730,15 @@ map<string, Json::Value> CommandLineInterface::parseAstFromInput()
void CommandLineInterface::createFile(string const& _fileName, string const& _data)
{
namespace fs = boost::filesystem;
// create directory if not existent
fs::path p(m_args.at(g_argOutputDir).as<string>());
// Do not try creating the directory if the first item is . or ..
if (p.filename() != "." && p.filename() != "..")
fs::create_directories(p);
string pathName = (p / _fileName).string();
fs::path outputDir(m_args.at(g_argOutputDir).as<string>());
// NOTE: create_directories() raises an exception if the path consists solely of '.' or '..'
// (or equivalent such as './././.'). Paths like 'a/b/.' and 'a/b/..' are fine though.
// The simplest workaround is to use an absolute path.
fs::create_directories(fs::absolute(outputDir));
string pathName = (outputDir / _fileName).string();
if (fs::exists(pathName) && !m_args.count(g_strOverwrite))
{
serr() << "Refusing to overwrite existing file \"" << pathName << "\" (use --" << g_strOverwrite << " to force)." << endl;