From 9aafa32825f17f6e66c0fd6f6747c28b1402069f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 25 Jan 2019 01:59:42 +0000 Subject: [PATCH] Disallow empty import statements --- Changelog.md | 2 +- libsolidity/interface/CompilerStack.cpp | 2 ++ libsolidity/parsing/Parser.cpp | 2 ++ test/libsolidity/syntaxTests/parsing/import_empty.sol | 3 +++ 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/libsolidity/syntaxTests/parsing/import_empty.sol diff --git a/Changelog.md b/Changelog.md index bc41fb810..ff635c208 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,10 +1,10 @@ ### 0.5.4 (unreleased) Bugfixes: + * Parser: Disallow empty import statements. * Type system: Properly report packed encoded size for arrays and structs (mostly unused until now). - Language Features: diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 9e4da62d8..0c140887c 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -681,6 +681,8 @@ StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string for (auto const& node: _ast.nodes()) if (ImportDirective const* import = dynamic_cast(node.get())) { + solAssert(!import->path().empty(), "Import path cannot be empty."); + string importPath = dev::absolutePath(import->path(), _sourcePath); // The current value of `path` is the absolute path as seen from this source file. // We first have to apply remappings before we can store the actual absolute path diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 35476a76f..8cbac5a29 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -221,6 +221,8 @@ ASTPointer Parser::parseImportDirective() fatalParserError("Expected import path."); path = getLiteralAndAdvance(); } + if (path->empty()) + fatalParserError("Import path cannot be empty."); nodeFactory.markEndPosition(); expectToken(Token::Semicolon); return nodeFactory.createNode(path, unitAlias, move(symbolAliases)); diff --git a/test/libsolidity/syntaxTests/parsing/import_empty.sol b/test/libsolidity/syntaxTests/parsing/import_empty.sol new file mode 100644 index 000000000..1853f6ec3 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/import_empty.sol @@ -0,0 +1,3 @@ +import ""; +// ---- +// ParserError: (9-10): Import path cannot be empty.