[PATCH] checkpatch: Flag spam header (X-Spam-Report) to prevent spurious warnings

From: John 'Warthog9' Hawley (VMware)
Date: Tue Mar 21 2017 - 12:31:52 EST


Spamassassin sticks a long (~79 character) long string after a
line that has a single space in it. The line with space causes
checkpatch to erroniously think that it's in the content body, as
opposed to headers and thus flag a mail header as an unwrapped long
comment line.

This flags when X-Spam-Report is found, till an e-mail
body indicator (blank line, /^[/n/r]*/) is found, blocking setting
$in_commit_log. When found, unsets itself allowing the rest of
the detection to function normally.

Reported-by: Darren Hart (VMware) <dvhart@xxxxxxxxxxxxx>
Signed-off-by: John 'Warthog9' Hawley (VMware) <warthog9@xxxxxxxxxxxxxx>
---
scripts/checkpatch.pl | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index baa3c7b..d2ce89a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2134,6 +2134,7 @@ sub process {
my $signoff = 0;
my $is_patch = 0;
my $in_header_lines = $file ? 0 : 1;
+ my $found_spam_header = 0;
my $in_commit_log = 0; #Scanning lines before patch
my $has_commit_log = 0; #Encountered lines before patch
my $commit_log_possible_stack_dump = 0;
@@ -2279,6 +2280,12 @@ sub process {

my $rawline = $rawlines[$linenr - 1];

+#if we encounter a spamassassin mail header, mark it
+ if ($in_header_lines == 1 && $line =~ /^X-Spam-Report:/) {
+ #mail header found, this needs to be flagged
+ $found_spam_header = 1;
+ }
+
#extract the line range in the file after the patch is applied
if (!$in_commit_log &&
$line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
@@ -2627,9 +2634,15 @@ sub process {

# Check if it's the start of a commit log
# (not a header line and we haven't seen the patch filename)
+ if ($in_header_lines && $found_spam_header && $line =~ /^[\n\r]*$/) {
+ # we are now past the header info that could be confusing
+ $found_spam_header = 0;
+ }
+
if ($in_header_lines && $realfile =~ /^$/ &&
!($rawline =~ /^\s+\S/ ||
- $rawline =~ /^(commit\b|from\b|[\w-]+:).*$/i)) {
+ $rawline =~ /^(commit\b|from\b|[\w-]+:).*$/i) &&
+ !$found_spam_header) {
$in_header_lines = 0;
$in_commit_log = 1;
$has_commit_log = 1;
--
2.5.5