From dcfaa520c4638a67052a4ff4a2a820be68750ad7 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 17 Sep 2020 10:34:20 +0300 Subject: bpo-41715: Fix potential catastrofic backtracking in c_analyzer. (GH-22091) --- Tools/c-analyzer/c_analyzer/common/info.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tools/c-analyzer/c_analyzer/common/info.py b/Tools/c-analyzer/c_analyzer/common/info.py index 3f3f8c5..1a853a4 100644 --- a/Tools/c-analyzer/c_analyzer/common/info.py +++ b/Tools/c-analyzer/c_analyzer/common/info.py @@ -9,7 +9,8 @@ from .util import classonly, _NTBase UNKNOWN = '???' -NAME_RE = re.compile(r'^([a-zA-Z]|_\w*[a-zA-Z]\w*|[a-zA-Z]\w*)$') +# Does not start with digit and contains at least one letter. +NAME_RE = re.compile(r'(?!\d)(?=.*?[A-Za-z])\w+', re.ASCII) class ID(_NTBase, namedtuple('ID', 'filename funcname name')): @@ -50,17 +51,16 @@ class ID(_NTBase, namedtuple('ID', 'filename funcname name')): """Fail if the object is invalid (i.e. init with bad data).""" if not self.name: raise TypeError('missing name') - else: - if not NAME_RE.match(self.name): - raise ValueError( - f'name must be an identifier, got {self.name!r}') + if not NAME_RE.fullmatch(self.name): + raise ValueError( + f'name must be an identifier, got {self.name!r}') # Symbols from a binary might not have filename/funcname info. if self.funcname: if not self.filename: raise TypeError('missing filename') - if not NAME_RE.match(self.funcname) and self.funcname != UNKNOWN: + if not NAME_RE.fullmatch(self.funcname) and self.funcname != UNKNOWN: raise ValueError( f'name must be an identifier, got {self.funcname!r}') -- cgit v0.12