Merge pull request #3570 from ethereum/assembly-oversized-literals

Raise error on oversized number literals in assembly
This commit is contained in:
chriseth 2018-02-22 14:42:52 +01:00 committed by GitHub
commit ca35963f84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 0 deletions

View File

@ -6,6 +6,7 @@ Features:
* Type Checker: Disallow uninitialized storage pointers as experimental 0.5.0 feature.
Bugfixes:
* Assembly: Raise error on oversized number literals in assembly.
* JSON-AST: Add "documentation" property to function, event and modifier definition.
* Resolver: Properly determine shadowing for imports with aliases.
* Standalone Assembly: Do not ignore input after closing brace of top level block.

View File

@ -82,6 +82,19 @@ bool AsmAnalyzer::operator()(assembly::Literal const& _literal)
);
return false;
}
else if (_literal.kind == assembly::LiteralKind::Number && bigint(_literal.value) > u256(-1))
{
m_errorReporter.typeError(
_literal.location,
"Number literal too large (> 256 bits)"
);
return false;
}
else if (_literal.kind == assembly::LiteralKind::Boolean)
{
solAssert(m_flavour == AsmFlavour::IULIA, "");
solAssert(_literal.value == "true" || _literal.value == "false", "");
}
m_info.stackHeightInfo[&_literal] = m_stackHeight;
return true;
}

View File

@ -228,6 +228,7 @@ BOOST_AUTO_TEST_CASE(number_literals)
CHECK_ERROR("{ let x:u256 := .1:u256 }", ParserError, "Invalid number literal.");
CHECK_ERROR("{ let x:u256 := 1e5:u256 }", ParserError, "Invalid number literal.");
CHECK_ERROR("{ let x:u256 := 67.235:u256 }", ParserError, "Invalid number literal.");
CHECK_ERROR("{ let x:u256 := 0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff:u256 }", TypeError, "Number literal too large (> 256 bits)");
}
BOOST_AUTO_TEST_CASE(builtin_types)

View File

@ -390,6 +390,7 @@ BOOST_AUTO_TEST_CASE(number_literals)
CHECK_PARSE_ERROR("{ let x := .1 }", ParserError, "Invalid number literal.");
CHECK_PARSE_ERROR("{ let x := 1e5 }", ParserError, "Invalid number literal.");
CHECK_PARSE_ERROR("{ let x := 67.235 }", ParserError, "Invalid number literal.");
CHECK_STRICT_ERROR("{ let x := 0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff }", TypeError, "Number literal too large (> 256 bits)");
}
BOOST_AUTO_TEST_CASE(function_definitions)