diff mbox series

[nanbield,23/33] patchtest-send-results: check max line length, simplify responses

Message ID 5be9766d5c70e9b4e9ff57ba73e582f1dd6a18bf.1700496737.git.steve@sakoman.com
State New, archived
Headers show
Series [nanbield,01/33] libsndfile1: fix CVE-2022-33065 | expand

Commit Message

Steve Sakoman Nov. 20, 2023, 4:38 p.m. UTC
From: Trevor Gamblin <tgamblin@baylibre.com>

Check that the maximum line length of the testresult file is less than
220 characters, to help guard against malicious changes being sent in
email responses. If any line exceeds this length, replace the normal
testresults used in the response with a line stating that tests failed,
but the results could not be processed. Also clean up the respone
substrings slightly to go along with the change.

Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit b0d53cf587dc9afb97f00c1089e45b758e96dd7c)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
---
 scripts/patchtest-send-results | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/scripts/patchtest-send-results b/scripts/patchtest-send-results
index bb4604aeaf..078651ec38 100755
--- a/scripts/patchtest-send-results
+++ b/scripts/patchtest-send-results
@@ -25,12 +25,8 @@  more information:\n\n---\n"""
 
 suggestions = """\n---\n\nPlease address the issues identified and
 submit a new revision of the patch, or alternatively, reply to this
-email with an explanation of why the patch format should be accepted.
-Note that patchtest may report failures in the merge-on-head test for
-patches that are part of a series if they rely on changes from
-preceeding entries.
-
-If you believe these results are due to an error in patchtest, please
+email with an explanation of why the patch format should be accepted. If
+you believe these results are due to an error in patchtest, please
 submit a bug at https://bugzilla.yoctoproject.org/ (use the 'Patchtest'
 category under 'Yocto Project Subprojects'). Thank you!"""
 
@@ -52,8 +48,6 @@  testresult = None
 with open(result_file, "r") as f:
     testresult = f.read()
 
-reply_contents = greeting + testresult + suggestions
-
 # we know these patch files will only contain a single patch, so only
 # worry about the first element for getting the subject
 mbox = mailbox.mbox(args.patch)
@@ -61,6 +55,13 @@  mbox_subject = mbox[0]['subject']
 subject_line = f"Patchtest results for {mbox_subject}"
 
 if "FAIL" in testresult:
+    reply_contents = None
+    if len(max(open(result_file, 'r'), key=len)) > 220:
+        warning = "Tests failed for the patch, but the results log could not be processed due to excessive result line length."
+        reply_contents = greeting + warning + suggestions
+    else:
+        reply_contents = greeting + testresult + suggestions
+
     ses_client = boto3.client('ses', region_name='us-west-2')
     response = ses_client.send_email(
         Source='patchtest@automation.yoctoproject.org',