Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Maxim Cournoyer <maxim.cournoyer@gmail.com>
Subject: [PATCH v3 3/3] send-email: detect empty blank lines in command output
Date: Tue, 25 Apr 2023 14:50:13 -0400	[thread overview]
Message-ID: <20230425185013.14351-4-maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <20230425185013.14351-1-maxim.cournoyer@gmail.com>

The email format does not allow blank lines in headers; detect such
input and report it as malformed and add a test for it.

Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
---
 git-send-email.perl   | 12 ++++++++++--
 t/t9001-send-email.sh | 17 +++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 666b37adc9..5adcbbeb49 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -2008,14 +2008,22 @@ sub process_file {
 	}
 }
 
-# Execute a command and return its output lines as an array.
+# Execute a command and return its output lines as an array.  Blank
+# lines which do not appear at the end of the output are reported as
+# errors.
 sub execute_cmd {
 	my ($prefix, $cmd, $file) = @_;
 	my @lines = ();
+	my $seen_blank_line = 0;
 	open my $fh, "-|", "$cmd \Q$file\E"
 		or die sprintf(__("(%s) Could not execute '%s'"), $prefix, $cmd);
 	while (my $line = <$fh>) {
-		last if $line =~ /^$/;
+		die sprintf(__("(%s) Malformed output from '%s'"), $prefix, $cmd)
+		    if $seen_blank_line;
+		if ($line =~ /^$/) {
+			$seen_blank_line = $line =~ /^$/;
+			next;
+		}
 		push @lines, $line;
 	}
 	close $fh
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 230f436f23..6701dd8848 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -445,6 +445,23 @@ FoldedField: This is a tale
 	grep "^FoldedField: This is a tale best told using multiple lines.$" msgtxt1
 '
 
+# Blank lines in the middle of the output of a command are invalid.
+test_expect_success $PREREQ 'malform output reported on blank lines in command output' '
+	clean_fake_sendmail &&
+	cp $patches headercmd.patch &&
+	write_script headercmd-malformed-output <<-\EOF &&
+	echo "X-Debbugs-CC: someone@example.com
+
+SomeOtherField: someone-else@example.com"
+	EOF
+	! git send-email \
+		--from="Example <nobody@example.com>" \
+		--to=nobody@example.com \
+		--header-cmd=./headercmd-malformed-output \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		headercmd.patch
+'
+
 test_expect_success $PREREQ 'reject long lines' '
 	z8=zzzzzzzz &&
 	z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
-- 
2.39.2


  parent reply	other threads:[~2023-04-25 18:52 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-23 12:27 [PATCH 0/2] send-email: add --header-cmd option Maxim Cournoyer
2023-04-23 12:27 ` [PATCH 1/2] send-email: extract execute_cmd from recipients_cmd Maxim Cournoyer
2023-04-24 21:46   ` Junio C Hamano
2023-04-25  1:55     ` Maxim Cournoyer
2023-04-23 12:27 ` [PATCH 2/2] send-email: add --header-cmd option Maxim Cournoyer
2023-04-24 22:09   ` Junio C Hamano
2023-04-25 16:22     ` Maxim Cournoyer
2023-04-25 16:29       ` Junio C Hamano
2023-04-25 18:50         ` [PATCH v3 0/3] " Maxim Cournoyer
2023-04-25 18:50           ` [PATCH v3 1/3] send-email: extract execute_cmd from recipients_cmd Maxim Cournoyer
2023-04-25 18:50           ` [PATCH v3 2/3] send-email: add --header-cmd option Maxim Cournoyer
2023-04-25 18:50           ` Maxim Cournoyer [this message]
2023-04-25 18:53         ` [PATCH 2/2] " Maxim Cournoyer
2023-05-01 14:38         ` [PATCH v4 0/3] " Maxim Cournoyer
2023-05-01 14:38           ` [PATCH v4 1/3] send-email: extract execute_cmd from recipients_cmd Maxim Cournoyer
2023-05-01 14:38           ` [PATCH v4 2/3] send-email: add --header-cmd, --no-header-cmd options Maxim Cournoyer
2023-05-01 14:38           ` [PATCH v4 3/3] send-email: detect empty blank lines in command output Maxim Cournoyer
2023-05-08 15:07           ` [PATCH v4 0/3] send-email: add --header-cmd option Maxim Cournoyer
2023-05-08 16:59             ` Eric Sunshine
2023-05-08 19:18               ` Maxim Cournoyer
2023-04-25 16:26     ` [PATCH v2 0/2] " Maxim Cournoyer
2023-04-25 16:26       ` [PATCH v2 1/2] send-email: extract execute_cmd from recipients_cmd Maxim Cournoyer
2023-04-25 17:04         ` Eric Sunshine
2023-04-25 19:09           ` Maxim Cournoyer
2023-05-02 18:39             ` Felipe Contreras
2023-05-02 20:46               ` Maxim Cournoyer
2023-05-02 21:50                 ` Felipe Contreras
2023-04-25 16:26       ` [PATCH v2 2/2] send-email: add --header-cmd option Maxim Cournoyer
2023-04-24 21:45 ` [PATCH 0/2] " Junio C Hamano
2023-04-25  1:50   ` Maxim Cournoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230425185013.14351-4-maxim.cournoyer@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).