aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/parsing/ParserBase.h
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-08-24 17:14:01 +0800
committerGitHub <noreply@github.com>2017-08-24 17:14:01 +0800
commit8af6f193bcf279381df3cca51b179b48e9cf5d5d (patch)
tree145ac3b1ed28a705d79f79ffd6366f5ad93d3aff /libsolidity/parsing/ParserBase.h
parent9c74473a9b08bfc58d97a46aceb8869c24095276 (diff)
parent628b54ce351dd5de8ec34aa8c2c23f2fd0a77d90 (diff)
downloaddexon-solidity-8af6f193bcf279381df3cca51b179b48e9cf5d5d.tar
dexon-solidity-8af6f193bcf279381df3cca51b179b48e9cf5d5d.tar.gz
dexon-solidity-8af6f193bcf279381df3cca51b179b48e9cf5d5d.tar.bz2
dexon-solidity-8af6f193bcf279381df3cca51b179b48e9cf5d5d.tar.lz
dexon-solidity-8af6f193bcf279381df3cca51b179b48e9cf5d5d.tar.xz
dexon-solidity-8af6f193bcf279381df3cca51b179b48e9cf5d5d.tar.zst
dexon-solidity-8af6f193bcf279381df3cca51b179b48e9cf5d5d.zip
Merge pull request #2770 from ethereum/recursionInAsm
Also prevent too much recursion in the assembly parser.
Diffstat (limited to 'libsolidity/parsing/ParserBase.h')
-rw-r--r--libsolidity/parsing/ParserBase.h20
1 files changed, 20 insertions, 0 deletions
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;
};
}