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.

Signed-off-by: Aaron Conole <[email protected]>
---
 utilities/checkpatch.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index 38d6f02c79..d18a8aacff 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -158,7 +158,7 @@ __regex_has_xxx_mark = re.compile(r'.*xxx.*', re.IGNORECASE)
 __regex_added_doc_rst = re.compile(
                     r'\ndiff .*Documentation/.*rst\nnew file mode')
 __regex_empty_return = re.compile(r'\s*return;')
-__regex_if_macros = re.compile(r'^ +(%s) \([\S]([\s\S]+[\S])*\) { +\\' %
+__regex_if_macros = re.compile(r'^ +(%s) \([\S][\s\S]*?[\S]\) { +\\' %
                                __parenthesized_constructs)
 __regex_nonascii_characters = re.compile("[^\u0000-\u007f]")
 __regex_efgrep = re.compile(r'.*[ef]grep.*$')
-- 
2.53.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to