aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/parsing
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-08-21 18:33:29 +0800
committerchriseth <chris@ethereum.org>2017-08-22 18:44:22 +0800
commit692e4c57e83607f21d0c1b1b735585b3b63564f3 (patch)
tree91d8ba9a3d9293282611505380f9040fb527ef1c /libsolidity/parsing
parent97cb571ba49b81bd20b840e20f27c2cf55730d81 (diff)
downloaddexon-solidity-692e4c57e83607f21d0c1b1b735585b3b63564f3.tar.gz
dexon-solidity-692e4c57e83607f21d0c1b1b735585b3b63564f3.tar.zst
dexon-solidity-692e4c57e83607f21d0c1b1b735585b3b63564f3.zip
Check recursion depth in assembly parser.
Diffstat (limited to 'libsolidity/parsing')
-rw-r--r--libsolidity/parsing/Parser.cpp32
-rw-r--r--libsolidity/parsing/Parser.h7
-rw-r--r--libsolidity/parsing/ParserBase.cpp13
-rw-r--r--libsolidity/parsing/ParserBase.h20
4 files changed, 33 insertions, 39 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index 7455cbca..1ab38f82 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -64,25 +64,6 @@ private:
SourceLocation m_location;
};
-/// Utility class that creates an error and throws an exception if the
-/// recursion depth is too deep.
-class Parser::RecursionGuard
-{
-public:
- explicit RecursionGuard(Parser& _parser):
- m_parser(_parser)
- {
- m_parser.increaseRecursionDepth();
- }
- ~RecursionGuard()
- {
- m_parser.decreaseRecursionDepth();
- }
-
-private:
- Parser& m_parser;
-};
-
ASTPointer<SourceUnit> Parser::parse(shared_ptr<Scanner> const& _scanner)
{
try
@@ -1542,19 +1523,6 @@ ASTPointer<ParameterList> Parser::createEmptyParameterList()
return nodeFactory.createNode<ParameterList>(vector<ASTPointer<VariableDeclaration>>());
}
-void Parser::increaseRecursionDepth()
-{
- m_recursionDepth++;
- if (m_recursionDepth >= 4096)
- fatalParserError("Maximum recursion depth reached during parsing.");
-}
-
-void Parser::decreaseRecursionDepth()
-{
- solAssert(m_recursionDepth > 0, "");
- m_recursionDepth--;
-}
-
string Parser::currentTokenName()
{
Token::Value token = m_scanner->currentToken();
diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h
index 0f74880c..cfdfea7e 100644
--- a/libsolidity/parsing/Parser.h
+++ b/libsolidity/parsing/Parser.h
@@ -41,7 +41,6 @@ public:
private:
class ASTNodeFactory;
- class RecursionGuard;
struct VarDeclParserOptions
{
@@ -165,14 +164,8 @@ private:
/// Creates an empty ParameterList at the current location (used if parameters can be omitted).
ASTPointer<ParameterList> createEmptyParameterList();
- /// Increases the recursion depth and throws an exception if it is too deep.
- void increaseRecursionDepth();
- void decreaseRecursionDepth();
-
/// Flag that signifies whether '_' is parsed as a PlaceholderStatement or a regular identifier.
bool m_insideModifier = false;
- /// Current recursion depth during parsing.
- size_t m_recursionDepth = 0;
};
}
diff --git a/libsolidity/parsing/ParserBase.cpp b/libsolidity/parsing/ParserBase.cpp
index 5657c2c0..db988739 100644
--- a/libsolidity/parsing/ParserBase.cpp
+++ b/libsolidity/parsing/ParserBase.cpp
@@ -101,6 +101,19 @@ void ParserBase::expectToken(Token::Value _value)
m_scanner->next();
}
+void ParserBase::increaseRecursionDepth()
+{
+ m_recursionDepth++;
+ if (m_recursionDepth >= 4096)
+ fatalParserError("Maximum recursion depth reached during parsing.");
+}
+
+void ParserBase::decreaseRecursionDepth()
+{
+ solAssert(m_recursionDepth > 0, "");
+ m_recursionDepth--;
+}
+
void ParserBase::parserError(string const& _description)
{
m_errorReporter.parserError(SourceLocation(position(), position(), sourceName()), _description);
diff --git a/libsolidity/parsing/ParserBase.h b/libsolidity/parsing/ParserBase.h
index 48733fc1..fd0de0d1 100644
--- a/libsolidity/parsing/ParserBase.h
+++ b/libsolidity/parsing/ParserBase.h
@@ -41,6 +41,20 @@ public:
std::shared_ptr<std::string const> const& sourceName() const;
protected:
+ /// Utility class that creates an error and throws an exception if the
+ /// recursion depth is too deep.
+ class RecursionGuard
+ {
+ public:
+ explicit RecursionGuard(ParserBase& _parser): m_parser(_parser)
+ {
+ m_parser.increaseRecursionDepth();
+ }
+ ~RecursionGuard() { m_parser.decreaseRecursionDepth(); }
+ private:
+ ParserBase& m_parser;
+ };
+
/// Start position of the current token
int position() const;
/// End position of the current token
@@ -56,6 +70,10 @@ protected:
Token::Value advance();
///@}
+ /// Increases the recursion depth and throws an exception if it is too deep.
+ void increaseRecursionDepth();
+ void decreaseRecursionDepth();
+
/// Creates a @ref ParserError and annotates it with the current position and the
/// given @a _description.
void parserError(std::string const& _description);
@@ -67,6 +85,8 @@ protected:
std::shared_ptr<Scanner> m_scanner;
/// The reference to the list of errors and warning to add errors/warnings during parsing
ErrorReporter& m_errorReporter;
+ /// Current recursion depth during parsing.
+ size_t m_recursionDepth = 0;
};
}