From 5a7214beb9f40b137f7b8d4244a2fdcabc604c1d Mon Sep 17 00:00:00 2001 From: Markus Linnala Date: Tue, 9 May 2023 15:48:41 +0300 Subject: [PATCH] bugfix: JinjaAnalysis: handle recursive macros --- ctf/analysis/JinjaAnalysis.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ctf/analysis/JinjaAnalysis.py b/ctf/analysis/JinjaAnalysis.py index de9f240..316098c 100644 --- a/ctf/analysis/JinjaAnalysis.py +++ b/ctf/analysis/JinjaAnalysis.py @@ -16,8 +16,9 @@ class JinjaMacroChange: - def __init__(self, name): + def __init__(self, name, seen=None): self.name = name + self.seen = set() if seen is None else seen self.higher_macros = [] self.in_rules = set() self.in_templates = set() @@ -47,7 +48,12 @@ def find_usages(self): if content_file.endswith(".jinja"): higher_macros = self.find_where_macro_used(self.name, content_file) for macro in higher_macros: - higher_macro_class = JinjaMacroChange(macro) + # Avoid recursion + if macro in self.seen: + continue + new_seen = self.seen.copy() + new_seen.add(macro) + higher_macro_class = JinjaMacroChange(macro, new_seen) self.higher_macros.append(higher_macro_class) else: self.parse_macro_usage(content_file)