threads / patch / 34195

patch, 2 partssend-email: sanitize author when writing From line

Subject: [PATCH 1/2] send-email: sanitize author when writing From line

## tl;dr

3 messages between Jun 18, 2013 and Jun 18, 2013. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Michael S. Tsirkin· Jun 18, 2013, 12:49 UTC · lore

sender is now sanitized, but we didn't sanitize author when checking whether From: line is needed in the message body. As a result git started writing duplicate From lines when author matched sender and has utf8 characters.

Reported-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 git-send-email.perl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Show changes to git-send-email.perl +3 −2
diff --git a/git-send-email.perl b/git-send-email.perl
index 671762b..ecbf56f 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1259,6 +1259,7 @@ foreach my $t (@files) {
 	open my $fh, "<", $t or die "can't open file $t";
 
 	my $author = undef;
+	my $sauthor = undef;
 	my $author_encoding;
 	my $has_content_type;
 	my $body_encoding;
@@ -1297,7 +1298,7 @@ foreach my $t (@files) {
 			}
 			elsif (/^From:\s+(.*)$/i) {
 				($author, $author_encoding) = unquote_rfc2047($1);
-				my $sauthor = sanitize_address($author);
+				$sauthor = sanitize_address($author);
 				next if $suppress_cc{'author'};
 				next if $suppress_cc{'self'} and $sauthor eq $sender;
 				printf("(mbox) Adding cc: %s from line '%s'\n",
@@ -1393,7 +1394,7 @@ foreach my $t (@files) {
 		$subject = quote_subject($subject, $auto_8bit_encoding);
 	}
 
-	if (defined $author and $author ne $sender) {
+	if (defined $sauthor and $sauthor ne $sender) {
 		$message = "From: $author\n\n$message";
 		if (defined $author_encoding) {
 			if ($has_content_type) {
-- 
MST
Michael S. Tsirkin· Jun 18, 2013, 12:49 UTC · re: Michael S. Tsirkin · lore

[PATCH 2/2] send-email: add test for duplicate utf8 name

Verify that author name is not duplicated if it matches sender, even if it is in utf8.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 t/t9001-send-email.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Show changes to t/t9001-send-email.sh +13 −0
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 9f46f22..cef884f 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -956,6 +956,19 @@ test_expect_success $PREREQ 'utf8 author is correctly passed on' '
 	grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
 '
 
+test_expect_success $PREREQ 'utf8 sender is not duplicated' '
+	clean_fake_sendmail &&
+	test_commit weird_sender &&
+	test_when_finished "git reset --hard HEAD^" &&
+	git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
+	git format-patch --stdout -1 >funny_name.patch &&
+	git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
+	  --to=nobody@example.com \
+	  --smtp-server="$(pwd)/fake.sendmail" \
+	  funny_name.patch &&
+	test `grep "^From:" msgtxt1|wc -l` -eq 1
+'
+
 test_expect_success $PREREQ 'sendemail.composeencoding works' '
 	clean_fake_sendmail &&
 	git config sendemail.composeencoding iso-8859-1 &&
-- 
MST
SZEDER Gábor· Jun 18, 2013, 13:55 UTC · re: Michael S. Tsirkin · lore

Re: [PATCH 2/2] send-email: add test for duplicate utf8 name

Hi Michael,
thanks for the quick turnaround.
On Tue, Jun 18, 2013 at 03:49:29PM +0300, Michael S. Tsirkin wrote:
Show 27 quoted lines
> Verify that author name is not duplicated if it matches
> sender, even if it is in utf8.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  t/t9001-send-email.sh | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
> index 9f46f22..cef884f 100755
> --- a/t/t9001-send-email.sh
> +++ b/t/t9001-send-email.sh
> @@ -956,6 +956,19 @@ test_expect_success $PREREQ 'utf8 author is correctly passed on' '
>  	grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
>  '
>  
> +test_expect_success $PREREQ 'utf8 sender is not duplicated' '
> +	clean_fake_sendmail &&
> +	test_commit weird_sender &&
> +	test_when_finished "git reset --hard HEAD^" &&
> +	git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
> +	git format-patch --stdout -1 >funny_name.patch &&
> +	git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
> +	  --to=nobody@example.com \
> +	  --smtp-server="$(pwd)/fake.sendmail" \
> +	  funny_name.patch &&
> +	test `grep "^From:" msgtxt1|wc -l` -eq 1
Perhaps you could use here
  grep "^From:" msgtxt1 >from &&
  test_line_count = 1 from
instead, to make it more debugging-friendly.
Show 7 quoted lines
> +'
> +
>  test_expect_success $PREREQ 'sendemail.composeencoding works' '
>  	clean_fake_sendmail &&
>  	git config sendemail.composeencoding iso-8859-1 &&
> -- 
> MST

I couldn't apply this patch with git am/apply on top of today's master for some reason, although the context lines seem to match exactly... in the end had to apply it manually.

Anyway, 1/2 fixes my problem, so:
Tested-by: SZEDER Gábor <szeder@ira.uka.de>

Thanks, Gábor

← back to recent threads