diff options
author | Aaron Conole <aconole@redhat.com> | 2021-09-03 10:28:02 -0400 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2021-09-08 21:29:03 +0200 |
commit | 00d3d4a7d3750ab1d907d58894ad817febce1cf7 (patch) | |
tree | 7300cc1dbb210ca91ea045c74b35999de53d5972 /tests | |
parent | 372b790f1d892f23bb82b651c92857d3b07fb799 (diff) | |
download | openvswitch-00d3d4a7d3750ab1d907d58894ad817febce1cf7.tar.gz |
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>
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/checkpatch.at | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/checkpatch.at b/tests/checkpatch.at index 0718acd99..f38214916 100755 --- a/tests/checkpatch.at +++ b/tests/checkpatch.at @@ -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 |