Skip to content

Commit 0ab118b

Browse files
committed
checkpatch.py: Fix a catastrophic backtracking issue.
The regex_if_macros accidentally implements a catastrophic backtracking case during matching because it forces a greedy match and evaluation that causes an explosion of combinations depending on how many blocks appear in a parenthesized expression. Consider an expression like: if (a b c d e f g h i j k) { The regex engine will have to create an exponential number of matches that can overload memory and cpu requirements. Fix this by switching the inner-content match to use a non-greedy approach. Fixes: aacad86 ("checkpatch: Fix regexp for if, while, etc inside macros.") Signed-off-by: Aaron Conole <aconole@redhat.com> Acked-by: Eelco Chaudron <echaudro@redhat.com>
1 parent 3023278 commit 0ab118b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

utilities/checkpatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def reset_counters():
158158
__regex_added_doc_rst = re.compile(
159159
r'\ndiff .*Documentation/.*rst\nnew file mode')
160160
__regex_empty_return = re.compile(r'\s*return;')
161-
__regex_if_macros = re.compile(r'^ +(%s) \([\S]([\s\S]+[\S])*\) { +\\' %
161+
__regex_if_macros = re.compile(r'^ +(%s) \([\S](?:[\s\S]*?[\S])?\) { +\\' %
162162
__parenthesized_constructs)
163163
__regex_nonascii_characters = re.compile("[^\u0000-\u007f]")
164164
__regex_efgrep = re.compile(r'.*[ef]grep.*$')

0 commit comments

Comments
 (0)