Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent infinite loops in conditions #3645

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cfnlint/context/conditions/_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def create_from_instance(
raise ValueError(f"Condition value {fn_v!r} must be a string")
sub_condition = all_conditions.get(fn_v)
try:
c = Condition.create_from_instance(sub_condition, all_conditions)
sub_all_conditions = all_conditions.copy()
del sub_all_conditions[fn_v]
c = Condition.create_from_instance(sub_condition, sub_all_conditions)
except Exception:
c = Condition.create_from_instance(
{"Fn::Equals": [None, None]}, all_conditions
Expand Down
4 changes: 3 additions & 1 deletion src/cfnlint/context/conditions/_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def create_from_instance(
raise ValueError("Conditions must be a object")
for k, v in conditions.items():
try:
obj[k] = Condition.create_from_instance(v, conditions)
other_conditions = conditions.copy()
del other_conditions[k]
obj[k] = Condition.create_from_instance(v, other_conditions)
except ValueError:
# this is a default condition so we can keep the name but it will
# not associate with another condition and will always be true/false
Expand Down
Loading