]> git.ipfire.org Git - thirdparty/git.git/commitdiff
send-email: detect empty blank lines in command output
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>
Mon, 1 May 2023 14:38:48 +0000 (10:38 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 May 2023 15:55:52 +0000 (08:55 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-send-email.perl
t/t9001-send-email.sh

index 32febe9af368b124f61fd5d05bde6c223b12fa6b..22a64e608f9f9289b0aec48d4a45f5c06d7f34dc 100755 (executable)
@@ -2026,14 +2026,22 @@ foreach my $t (@files) {
        }
 }
 
-# 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
index f10546acba79407624da409406384aa15e7e1b89..21d4f6a382a102cee0412a114741b80c8e1f21ed 100755 (executable)
@@ -460,6 +460,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 &&