mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
nodes/patterns: Fixed crashes when recursion occurred
This commit is contained in:
@@ -538,6 +538,10 @@ namespace hex::lang {
|
||||
|
||||
PatternData *pattern;
|
||||
|
||||
this->m_currRecursionDepth++;
|
||||
if (this->m_currRecursionDepth > this->m_recursionLimit)
|
||||
this->getConsole().abortEvaluation(hex::format("evaluation depth exceeds maximum of {0}. Use #pragma eval_depth <depth> to increase the maximum", this->m_recursionLimit));
|
||||
|
||||
if (auto builtinTypeNode = dynamic_cast<ASTNodeBuiltinType*>(type); builtinTypeNode != nullptr)
|
||||
return this->evaluateBuiltinType(builtinTypeNode);
|
||||
else if (auto typeDeclNode = dynamic_cast<ASTNodeTypeDecl*>(type); typeDeclNode != nullptr)
|
||||
@@ -553,6 +557,8 @@ namespace hex::lang {
|
||||
else
|
||||
this->getConsole().abortEvaluation("type could not be evaluated");
|
||||
|
||||
this->m_currRecursionDepth--;
|
||||
|
||||
if (!node->getName().empty())
|
||||
pattern->setTypeName(node->getName().data());
|
||||
|
||||
@@ -752,6 +758,7 @@ namespace hex::lang {
|
||||
try {
|
||||
for (const auto& node : ast) {
|
||||
this->m_endianStack.push_back(this->m_defaultDataEndian);
|
||||
this->m_currRecursionDepth = 0;
|
||||
|
||||
if (auto variableDeclNode = dynamic_cast<ASTNodeVariableDecl*>(node); variableDeclNode != nullptr) {
|
||||
this->m_globalMembers.push_back(this->evaluateVariable(variableDeclNode));
|
||||
|
||||
@@ -33,6 +33,16 @@ namespace hex::lang {
|
||||
} else
|
||||
return false;
|
||||
});
|
||||
|
||||
this->m_preprocessor->addPragmaHandler("eval_depth", [this](std::string value) {
|
||||
auto limit = strtol(value.c_str(), nullptr, 0);
|
||||
|
||||
if (limit <= 0)
|
||||
return false;
|
||||
|
||||
this->m_recursionLimit = limit;
|
||||
return true;
|
||||
});
|
||||
this->m_preprocessor->addDefaultPragmaHandlers();
|
||||
}
|
||||
|
||||
@@ -56,6 +66,9 @@ namespace hex::lang {
|
||||
return { };
|
||||
}
|
||||
|
||||
this->m_evaluator->setDefaultEndian(this->m_defaultEndian);
|
||||
this->m_evaluator->setRecursionLimit(this->m_recursionLimit);
|
||||
|
||||
auto tokens = this->m_lexer->lex(preprocessedCode.value());
|
||||
if (!tokens.has_value()) {
|
||||
this->m_currError = this->m_lexer->getError();
|
||||
|
||||
Reference in New Issue
Block a user