mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +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:
committed by
Ilya Maximets
parent
372b790f1d
commit
00d3d4a7d3
@@ -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:
|
||||
return False
|
||||
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:
|
||||
|
Reference in New Issue
Block a user