git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 3/3] send-email: detect empty blank lines in command output

From
Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date
Apr 25, 2023, 18:50 UTC
Message-ID
<20230425185013.14351-4-maxim.cournoyer@gmail.com>
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
Previous: Maxim CournoyerNext: Maxim Cournoyer
Message 12 of 30 in “send-email: add --header-cmd option”
  1. 0/2 send-email: add --header-cmd optionMaxim Cournoyer, Apr 23, 2023
  2. 1/2 send-email: extract execute_cmd from recipients_cmdMaxim Cournoyer, Apr 23, 2023
  3. Junio C HamanoApr 24, 2023
  4. Maxim CournoyerApr 25, 2023
  5. 2/2 send-email: add --header-cmd optionMaxim Cournoyer, Apr 23, 2023
  6. Junio C HamanoApr 24, 2023
  7. Maxim CournoyerApr 25, 2023
  8. Junio C HamanoApr 25, 2023
  9. 0/3 send-email: add --header-cmd optionMaxim Cournoyer, Apr 25, 2023
  10. 1/3 send-email: extract execute_cmd from recipients_cmdMaxim Cournoyer, Apr 25, 2023
  11. 2/3 send-email: add --header-cmd optionMaxim Cournoyer, Apr 25, 2023
  12. 3/3 send-email: detect empty blank lines in command outputMaxim Cournoyer, Apr 25, 2023
  13. Maxim CournoyerApr 25, 2023
  14. 0/3 send-email: add --header-cmd optionMaxim Cournoyer, May 1, 2023
  15. 1/3 send-email: extract execute_cmd from recipients_cmdMaxim Cournoyer, May 1, 2023
  16. 2/3 send-email: add --header-cmd, --no-header-cmd optionsMaxim Cournoyer, May 1, 2023
  17. 3/3 send-email: detect empty blank lines in command outputMaxim Cournoyer, May 1, 2023
  18. Maxim CournoyerMay 8, 2023
  19. Eric SunshineMay 8, 2023
  20. Maxim CournoyerMay 8, 2023
  21. 0/2 send-email: add --header-cmd optionMaxim Cournoyer, Apr 25, 2023
  22. 1/2 send-email: extract execute_cmd from recipients_cmdMaxim Cournoyer, Apr 25, 2023
  23. Eric SunshineApr 25, 2023
  24. Maxim CournoyerApr 25, 2023
  25. Felipe ContrerasMay 2, 2023
  26. Maxim CournoyerMay 2, 2023
  27. Felipe ContrerasMay 2, 2023
  28. 2/2 send-email: add --header-cmd optionMaxim Cournoyer, Apr 25, 2023
  29. Junio C HamanoApr 24, 2023
  30. Maxim CournoyerApr 25, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.