Skip to content

Commit

Permalink
Merge pull request ethereum#123 from chriseth/largeHexConstants
Browse files Browse the repository at this point in the history
Check invalid integer constants for functions accepting arbitrary arguments.
  • Loading branch information
chriseth committed Oct 7, 2015
2 parents ab433c9 + 35de036 commit b4f817d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
14 changes: 10 additions & 4 deletions libsolidity/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,15 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
{
// call by positional arguments
for (size_t i = 0; i < arguments.size(); ++i)
if (
!functionType->takesArbitraryParameters() &&
!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i])
)
{
auto const& argType = type(*arguments[i]);
if (functionType->takesArbitraryParameters())
{
if (auto t = dynamic_cast<IntegerConstantType const*>(argType.get()))
if (!t->integerType())
typeError(*arguments[i], "Integer constant too large.");
}
else if (!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i]))
typeError(
*arguments[i],
"Invalid type for argument in function call. "
Expand All @@ -837,6 +842,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
parameterTypes[i]->toString() +
" requested."
);
}
}
else
{
Expand Down
15 changes: 13 additions & 2 deletions test/libsolidity/SolidityNameAndTypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false)
try
{
sourceUnit = parser.parse(std::make_shared<Scanner>(CharStream(_source)));
NameAndTypeResolver resolver({});
resolver.registerDeclarations(*sourceUnit);
std::shared_ptr<GlobalContext> globalContext = make_shared<GlobalContext>();
NameAndTypeResolver resolver(globalContext->declarations());
resolver.registerDeclarations(*sourceUnit);

for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
Expand Down Expand Up @@ -2366,6 +2366,17 @@ BOOST_AUTO_TEST_CASE(non_initialized_references)
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text, true), Warning);
}

BOOST_AUTO_TEST_CASE(sha3_with_large_integer_constant)
{
char const* text = R"(
contract c
{
function f() { sha3(2**500); }
}
)";
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
}

BOOST_AUTO_TEST_CASE(cyclic_binary_dependency)
{
char const* text = R"(
Expand Down

0 comments on commit b4f817d

Please sign in to comment.