Skip to content

Commit

Permalink
Update regex to prevent a chance re.match will hang
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Mar 20, 2020
1 parent 58397f3 commit df72aaf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cfnlint/rules/functions/SubNeeded.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
SPDX-License-Identifier: MIT-0
"""
import re
import six
from cfnlint.rules import CloudFormationLintRule
from cfnlint.rules import RuleMatch

Expand Down Expand Up @@ -73,7 +74,7 @@ def _match_values(self, searchRegex, cfnelem, path):
values.extend(self._match_values(searchRegex, item, pathprop))
else:
# Leaf node
if isinstance(cfnelem, str) and re.match(searchRegex, cfnelem):
if isinstance(cfnelem, six.string_types) and re.match(searchRegex, cfnelem):
# Get all variables as seperate paths
regex = re.compile(r'(\$\{.*?\.?.*?})')
for variable in re.findall(regex, cfnelem):
Expand Down Expand Up @@ -110,11 +111,10 @@ def match(self, cfn):
matches = []

# Generic regex to match a string containing at least one ${parameter}
parameter_search = re.compile(r'^.*(\$\{.*\}.*(\$\{.*\}.*)*)$')
parameter_search = re.compile(r'^.*(\$\{[a-zA-Z0-9:._]*\}.*)*$')

# Get a list of paths to every leaf node string containing at least one ${parameter}
parameter_string_paths = self.match_values(parameter_search, cfn)

# We want to search all of the paths to check if each one contains an 'Fn::Sub'
for parameter_string_path in parameter_string_paths:
if parameter_string_path[0] in ['Parameters']:
Expand Down

0 comments on commit df72aaf

Please sign in to comment.