mirror of
https://github.com/pantor/inja.git
synced 2026-02-17 09:03:58 +00:00
Prevent local stack memory leakage when parsing (#302)
We need to resets current_block to a nullptr after parsing the template in `parse_into`, otherwise, current_block will refer to local stack space after we return from Parser::parse.
This commit is contained in:
@@ -573,6 +573,7 @@ class Parser {
|
|||||||
throw_parser_error("unmatched for");
|
throw_parser_error("unmatched for");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
current_block = nullptr;
|
||||||
return;
|
return;
|
||||||
case Token::Kind::Text: {
|
case Token::Kind::Text: {
|
||||||
current_block->nodes.emplace_back(std::make_shared<TextNode>(tok.text.data() - tmpl.content.c_str(), tok.text.size()));
|
current_block->nodes.emplace_back(std::make_shared<TextNode>(tok.text.data() - tmpl.content.c_str(), tok.text.size()));
|
||||||
@@ -617,6 +618,7 @@ class Parser {
|
|||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
current_block = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -2016,6 +2016,7 @@ class Parser {
|
|||||||
throw_parser_error("unmatched for");
|
throw_parser_error("unmatched for");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
current_block = nullptr;
|
||||||
return;
|
return;
|
||||||
case Token::Kind::Text: {
|
case Token::Kind::Text: {
|
||||||
current_block->nodes.emplace_back(std::make_shared<TextNode>(tok.text.data() - tmpl.content.c_str(), tok.text.size()));
|
current_block->nodes.emplace_back(std::make_shared<TextNode>(tok.text.data() - tmpl.content.c_str(), tok.text.size()));
|
||||||
@@ -2060,6 +2061,7 @@ class Parser {
|
|||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
current_block = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user