2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-04 16:25:17 +00:00

checkpatch: Avoid catastrophic backtracking.

As Frode Nordahl points out in [0], it is possible for the
python regex module to enter a case of catastrophic backtracking
which causes oscillation between states and hangs the checkpatch
script.

One suggested solution to these cases is to use an anchor[1] in
the regex, which should force the backtrack to exit early.
However, when I tested this, it didn't seem to improve anything
(since the start is already anchored, and trying to anchor the
end results in the same hang).

Instead, we explicitly check that the line ends with '\\' before
trying to match on the 'if-inside-a-macro' check.  A new check
is added to catch the case in checkpatch.

0: https://mail.openvswitch.org/pipermail/ovs-dev/2021-August/386881.html
1: https://stackoverflow.com/questions/22072406/preventing-any-backtracking-in-regex-past-a-specific-pattern

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Aaron Conole
2021-09-03 10:28:02 -04:00
committed by Ilya Maximets
parent 372b790f1d
commit 00d3d4a7d3
2 changed files with 23 additions and 3 deletions

View File

@@ -232,6 +232,22 @@ done
AT_CLEANUP
AT_SETUP([checkpatch - catastrophic backtracking])
dnl Special case this rather than using the above construct because sometimes a
dnl warning needs to be generated for line lengths (f.e. when the 'while'
dnl keyword is used).
try_checkpatch \
"COMMON_PATCH_HEADER
+ if (!b_ctx_in->chassis_rec || !b_ctx_in->br_int || !b_ctx_in->ovs_idl_txn)
" \
"ERROR: Inappropriate bracing around statement
#8 FILE: A.c:1:
if (!b_ctx_in->chassis_rec || !b_ctx_in->br_int || !b_ctx_in->ovs_idl_txn)
"
AT_CLEANUP
AT_SETUP([checkpatch - parenthesized constructs - for])
try_checkpatch \
"COMMON_PATCH_HEADER

View File

@@ -274,9 +274,13 @@ def if_and_for_end_with_bracket_check(line):
if not balanced_parens(line):
return True
if __regex_ends_with_bracket.search(line) is None and \
__regex_if_macros.match(line) is None:
if __regex_ends_with_bracket.search(line) is None:
if line.endswith("\\") and \
__regex_if_macros.match(line) is not None:
return True
else:
return False
if __regex_conditional_else_bracing.match(line) is not None:
return False
if __regex_conditional_else_bracing2.match(line) is not None: