Skip to content

Commit 3a7a18a

Browse files
apteryksgitster
authored andcommitted
send-email: detect empty blank lines in command output
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ba92106 commit 3a7a18a

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

git-send-email.perl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,14 +2026,22 @@ sub process_file {
20262026
}
20272027
}
20282028

2029-
# Execute a command and return its output lines as an array.
2029+
# Execute a command and return its output lines as an array. Blank
2030+
# lines which do not appear at the end of the output are reported as
2031+
# errors.
20302032
sub execute_cmd {
20312033
my ($prefix, $cmd, $file) = @_;
20322034
my @lines = ();
2035+
my $seen_blank_line = 0;
20332036
open my $fh, "-|", "$cmd \Q$file\E"
20342037
or die sprintf(__("(%s) Could not execute '%s'"), $prefix, $cmd);
20352038
while (my $line = <$fh>) {
2036-
last if $line =~ /^$/;
2039+
die sprintf(__("(%s) Malformed output from '%s'"), $prefix, $cmd)
2040+
if $seen_blank_line;
2041+
if ($line =~ /^$/) {
2042+
$seen_blank_line = $line =~ /^$/;
2043+
next;
2044+
}
20372045
push @lines, $line;
20382046
}
20392047
close $fh

t/t9001-send-email.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,23 @@ FoldedField: This is a tale
460460
grep "^FoldedField: This is a tale best told using multiple lines.$" msgtxt1
461461
'
462462

463+
# Blank lines in the middle of the output of a command are invalid.
464+
test_expect_success $PREREQ 'malform output reported on blank lines in command output' '
465+
clean_fake_sendmail &&
466+
cp $patches headercmd.patch &&
467+
write_script headercmd-malformed-output <<-\EOF &&
468+
echo "X-Debbugs-CC: [email protected]
469+
470+
SomeOtherField: [email protected]"
471+
EOF
472+
! git send-email \
473+
--from="Example <[email protected]>" \
474+
475+
--header-cmd=./headercmd-malformed-output \
476+
--smtp-server="$(pwd)/fake.sendmail" \
477+
headercmd.patch
478+
'
479+
463480
test_expect_success $PREREQ 'reject long lines' '
464481
z8=zzzzzzzz &&
465482
z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&

0 commit comments

Comments
 (0)