mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Be more strict about number literals in assembly.
This commit is contained in:
parent
83b90f3e8a
commit
2c5985de06
@ -12,6 +12,7 @@ Features:
|
|||||||
Bugfixes:
|
Bugfixes:
|
||||||
* Parser: Enforce commas between array and tuple elements.
|
* Parser: Enforce commas between array and tuple elements.
|
||||||
* Parser: Limit maximum recursion depth.
|
* Parser: Limit maximum recursion depth.
|
||||||
|
* Assembly Parser: Be more strict about number literals.
|
||||||
|
|
||||||
### 0.4.15 (2017-08-08)
|
### 0.4.15 (2017-08-08)
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
#include <libsolidity/inlineasm/AsmParser.h>
|
#include <libsolidity/inlineasm/AsmParser.h>
|
||||||
#include <libsolidity/parsing/Scanner.h>
|
#include <libsolidity/parsing/Scanner.h>
|
||||||
#include <libsolidity/interface/ErrorReporter.h>
|
#include <libsolidity/interface/ErrorReporter.h>
|
||||||
|
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -297,6 +300,8 @@ assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher)
|
|||||||
kind = LiteralKind::String;
|
kind = LiteralKind::String;
|
||||||
break;
|
break;
|
||||||
case Token::Number:
|
case Token::Number:
|
||||||
|
if (!isValidNumberLiteral(currentLiteral()))
|
||||||
|
fatalParserError("Invalid number literal.");
|
||||||
kind = LiteralKind::Number;
|
kind = LiteralKind::Number;
|
||||||
break;
|
break;
|
||||||
case Token::TrueLiteral:
|
case Token::TrueLiteral:
|
||||||
@ -501,3 +506,19 @@ string Parser::expectAsmIdentifier()
|
|||||||
expectToken(Token::Identifier);
|
expectToken(Token::Identifier);
|
||||||
return name;
|
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;
|
||||||
|
}
|
||||||
|
@ -75,6 +75,8 @@ protected:
|
|||||||
TypedName parseTypedName();
|
TypedName parseTypedName();
|
||||||
std::string expectAsmIdentifier();
|
std::string expectAsmIdentifier();
|
||||||
|
|
||||||
|
static bool isValidNumberLiteral(std::string const& _literal);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_julia = false;
|
bool m_julia = false;
|
||||||
};
|
};
|
||||||
|
@ -214,6 +214,14 @@ BOOST_AUTO_TEST_CASE(invalid_types)
|
|||||||
CHECK_ERROR("{ function f(a:invalid) {} }", TypeError, "\"invalid\" is not a valid type (user defined types are not yet supported).");
|
CHECK_ERROR("{ function f(a:invalid) {} }", TypeError, "\"invalid\" is not a valid type (user defined types are not yet supported).");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(number_literals)
|
||||||
|
{
|
||||||
|
BOOST_CHECK(successParse("{ let x:u256 := 1:u256 }"));
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(builtin_types)
|
BOOST_AUTO_TEST_CASE(builtin_types)
|
||||||
{
|
{
|
||||||
BOOST_CHECK(successParse("{ let x:bool := true:bool }"));
|
BOOST_CHECK(successParse("{ let x:bool := true:bool }"));
|
||||||
|
@ -339,6 +339,14 @@ BOOST_AUTO_TEST_CASE(blocks)
|
|||||||
BOOST_CHECK(successParse("{ let x := 7 { let y := 3 } { let z := 2 } }"));
|
BOOST_CHECK(successParse("{ let x := 7 { let y := 3 } { let z := 2 } }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(number_literals)
|
||||||
|
{
|
||||||
|
BOOST_CHECK(successParse("{ let x := 1 }"));
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_definitions)
|
BOOST_AUTO_TEST_CASE(function_definitions)
|
||||||
{
|
{
|
||||||
BOOST_CHECK(successParse("{ function f() { } function g(a) -> x { } }"));
|
BOOST_CHECK(successParse("{ function f() { } function g(a) -> x { } }"));
|
||||||
|
Loading…
Reference in New Issue
Block a user