aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-01-05 07:25:41 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-02-22 08:02:19 +0800
commitae02bb5aadfa49636f9931524dbc026c855201f1 (patch)
tree0328334a01d5198a6f17c97c8ad6fa0c46a52906
parentd01786f0aa4e128f70aea2bc53a8d3c61294a587 (diff)
downloaddexon-solidity-ae02bb5aadfa49636f9931524dbc026c855201f1.tar.gz
dexon-solidity-ae02bb5aadfa49636f9931524dbc026c855201f1.tar.zst
dexon-solidity-ae02bb5aadfa49636f9931524dbc026c855201f1.zip
Raise error on oversized number literals in assembly
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/inlineasm/AsmAnalysis.cpp8
-rw-r--r--test/libjulia/Parser.cpp1
-rw-r--r--test/libsolidity/InlineAssembly.cpp1
4 files changed, 11 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md
index f25b138b..ad92c94a 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -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.
diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp
index 2d6e58de..e672d5ef 100644
--- a/libsolidity/inlineasm/AsmAnalysis.cpp
+++ b/libsolidity/inlineasm/AsmAnalysis.cpp
@@ -82,6 +82,14 @@ 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;
+ }
m_info.stackHeightInfo[&_literal] = m_stackHeight;
return true;
}
diff --git a/test/libjulia/Parser.cpp b/test/libjulia/Parser.cpp
index 0a2dd815..ff9474c1 100644
--- a/test/libjulia/Parser.cpp
+++ b/test/libjulia/Parser.cpp
@@ -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)
diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp
index 70620f78..45fb54f8 100644
--- a/test/libsolidity/InlineAssembly.cpp
+++ b/test/libsolidity/InlineAssembly.cpp
@@ -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)