aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/inlineasm/AsmParser.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-08-21 18:08:29 +0800
committerchriseth <chris@ethereum.org>2017-08-21 19:31:28 +0800
commit2c5985de06b4ad35eaa77f3869e280440100c9cd (patch)
tree96fbdef7b3bf029d8f72ae9df53268375a952ca2 /libsolidity/inlineasm/AsmParser.cpp
parent83b90f3e8a3ee168ba00eff33c4443d00bbb8a57 (diff)
downloaddexon-solidity-2c5985de06b4ad35eaa77f3869e280440100c9cd.tar.gz
dexon-solidity-2c5985de06b4ad35eaa77f3869e280440100c9cd.tar.zst
dexon-solidity-2c5985de06b4ad35eaa77f3869e280440100c9cd.zip
Be more strict about number literals in assembly.
Diffstat (limited to 'libsolidity/inlineasm/AsmParser.cpp')
-rw-r--r--libsolidity/inlineasm/AsmParser.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp
index 133f70b1..1dcc42b8 100644
--- a/libsolidity/inlineasm/AsmParser.cpp
+++ b/libsolidity/inlineasm/AsmParser.cpp
@@ -23,6 +23,9 @@
#include <libsolidity/inlineasm/AsmParser.h>
#include <libsolidity/parsing/Scanner.h>
#include <libsolidity/interface/ErrorReporter.h>
+
+#include <boost/algorithm/string.hpp>
+
#include <ctype.h>
#include <algorithm>
@@ -297,6 +300,8 @@ assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher)
kind = LiteralKind::String;
break;
case Token::Number:
+ if (!isValidNumberLiteral(currentLiteral()))
+ fatalParserError("Invalid number literal.");
kind = LiteralKind::Number;
break;
case Token::TrueLiteral:
@@ -501,3 +506,19 @@ string Parser::expectAsmIdentifier()
expectToken(Token::Identifier);
return name;
}
+
+bool Parser::isValidNumberLiteral(string const& _literal)
+{
+ try
+ {
+ u256(_literal);
+ }
+ catch (...)
+ {
+ return false;
+ }
+ if (boost::starts_with(_literal, "0x"))
+ return true;
+ else
+ return _literal.find_first_not_of("0123456789") == string::npos;
+}