From 55bac0b95e3c3863210ddc3ba6f03b397760eb57 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Wed, 18 Mar 2020 20:50:09 -0500 Subject: [PATCH] Update regex to prevent a chance re.match will hang --- src/cfnlint/rules/functions/SubNeeded.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cfnlint/rules/functions/SubNeeded.py b/src/cfnlint/rules/functions/SubNeeded.py index 4d2427098c..87a1c288b2 100644 --- a/src/cfnlint/rules/functions/SubNeeded.py +++ b/src/cfnlint/rules/functions/SubNeeded.py @@ -3,6 +3,7 @@ SPDX-License-Identifier: MIT-0 """ import re +import six from cfnlint.rules import CloudFormationLintRule from cfnlint.rules import RuleMatch @@ -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): @@ -110,7 +111,7 @@ 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:.]*\}.*(\$\{[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)