Skip to content

Commit 0168619

Browse files
authored
Prevent infinite loops in conditions (#3645)
1 parent eba6a45 commit 0168619

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/cfnlint/context/conditions/_condition.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def create_from_instance(
6666
raise ValueError(f"Condition value {fn_v!r} must be a string")
6767
sub_condition = all_conditions.get(fn_v)
6868
try:
69-
c = Condition.create_from_instance(sub_condition, all_conditions)
69+
sub_all_conditions = all_conditions.copy()
70+
del sub_all_conditions[fn_v]
71+
c = Condition.create_from_instance(sub_condition, sub_all_conditions)
7072
except Exception:
7173
c = Condition.create_from_instance(
7274
{"Fn::Equals": [None, None]}, all_conditions

src/cfnlint/context/conditions/_conditions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def create_from_instance(
4141
raise ValueError("Conditions must be a object")
4242
for k, v in conditions.items():
4343
try:
44-
obj[k] = Condition.create_from_instance(v, conditions)
44+
other_conditions = conditions.copy()
45+
del other_conditions[k]
46+
obj[k] = Condition.create_from_instance(v, other_conditions)
4547
except ValueError:
4648
# this is a default condition so we can keep the name but it will
4749
# not associate with another condition and will always be true/false

0 commit comments

Comments
 (0)