From a8696c6d8e1d64f02f65c98818f89532b5694953 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 1 Nov 2016 00:17:53 +0000 Subject: LLL: do not accept '0x' as 0 --- liblll/Parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liblll/Parser.cpp b/liblll/Parser.cpp index 219d4f54..4d2736ba 100644 --- a/liblll/Parser.cpp +++ b/liblll/Parser.cpp @@ -100,7 +100,7 @@ void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out) qi::rule str = '"' > qi::lexeme[+(~qi::char_(std::string("\"") + '\0'))] > '"'; qi::rule strsh = '\'' > qi::lexeme[+(~qi::char_(std::string(" ;$@()[]{}:\n\t") + '\0'))]; qi::rule symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))]; - qi::rule intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]]; + qi::rule intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> +qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]]; qi::rule integer = intstr[qi::_val = px::construct(px::new_(qi::_1))]; qi::rule atom = integer[qi::_val = qi::_1] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1]; qi::rule seq = '{' > *element > '}'; -- cgit From 99b803cbcbe4f7a0806db12d53cb7152fde490ef Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 1 Nov 2016 00:19:25 +0000 Subject: LLL: () requires at least one parameter --- liblll/Parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liblll/Parser.cpp b/liblll/Parser.cpp index 4d2736ba..ad5e1885 100644 --- a/liblll/Parser.cpp +++ b/liblll/Parser.cpp @@ -109,7 +109,7 @@ void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out) qi::rule mstore = '[' > element > ']' > -qi::lit(":") > element; qi::rule sstore = qi::lit("[[") > element > qi::lit("]]") > -qi::lit(":") > element; qi::rule calldataload = qi::lit("$") > element; - qi::rule list = '(' > *element > ')'; + qi::rule list = '(' > +element > ')'; qi::rule extra = sload[tagNode<2>()] | mload[tagNode<1>()] | sstore[tagNode<4>()] | mstore[tagNode<3>()] | seq[tagNode<5>()] | calldataload[tagNode<6>()]; element = atom | list | extra; -- cgit From b1add657b76621952be100b4203dd2c8a466b9a1 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 1 Nov 2016 02:07:20 +0000 Subject: LLL: throw exceptions on invalid symbols --- liblll/CodeFragment.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index 35ad4e59..af7d7f0a 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -91,15 +91,11 @@ CodeFragment::CodeFragment(sp::utree const& _t, CompilerState& _s, bool _allowAS { auto it = _s.vars.find(s); if (it == _s.vars.end()) - { - bool ok; - tie(it, ok) = _s.vars.insert(make_pair(s, make_pair(_s.stackSize, 32))); - _s.stackSize += 32; - } + error(std::string("Symbol not found: ") + s); m_asm.append((u256)it->second.first); } else - error(); + error(s); break; } @@ -111,7 +107,9 @@ CodeFragment::CodeFragment(sp::utree const& _t, CompilerState& _s, bool _allowAS m_asm.append((u256)i); break; } - default: break; + default: + error("Unexpected fragment type"); + break; } } @@ -177,11 +175,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) { auto it = _s.vars.find(n); if (it == _s.vars.end()) - { - bool ok; - tie(it, ok) = _s.vars.insert(make_pair(n, make_pair(_s.stackSize, 32))); - _s.stackSize += 32; - } + error(std::string("Symbol not found: ") + s); return it->second.first; }; -- cgit From 4cecedcb49188a49ed70241f36e19ec8cb542a4c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 30 Nov 2016 00:16:25 +0000 Subject: LLL: update tests with the strict parser --- test/liblll/Parser.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/liblll/Parser.cpp b/test/liblll/Parser.cpp index fc91f3c5..0d5d9ea5 100644 --- a/test/liblll/Parser.cpp +++ b/test/liblll/Parser.cpp @@ -87,6 +87,8 @@ BOOST_AUTO_TEST_CASE(hexadecimals) char const* text = "0x1234"; BOOST_CHECK(successParse(text)); BOOST_CHECK_EQUAL(parse(text), R"(4660)"); + + BOOST_CHECK(!successParse("0x")); } BOOST_AUTO_TEST_CASE(sequence) @@ -169,7 +171,7 @@ BOOST_AUTO_TEST_CASE(list) BOOST_CHECK_EQUAL(parse(text), R"(( 1234 ))"); BOOST_CHECK(successParse("( 1234 5467 )")); - BOOST_CHECK(successParse("()")); + BOOST_CHECK(!successParse("()")); } BOOST_AUTO_TEST_SUITE_END() -- cgit