Skip to content

Commit 3c3bb51

Browse files
bebarinogitster
authored andcommitted
send-email: Don't leak To: headers between patches
If the first patch in a series has a To: header in the file and the second patch in the series doesn't the address from the first patch will be part of the To: addresses in the second patch. Fix this by treating the to list like the cc list. Have an initial to list come from the command line, user input and config options. Then build up a to list from each patch and concatenate the two together before sending the patch. Finally, reset the list after sending each patch so the To: headers from a patch don't get used for the next one. Reported-by: Viresh Kumar <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 21802cd commit 3c3bb51

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

git-send-email.perl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ sub format_2822_time {
138138
sub cleanup_compose_files();
139139

140140
# Variables we fill in automatically, or via prompting:
141-
my (@to,$no_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
141+
my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
142142
$initial_reply_to,$initial_subject,@files,
143143
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
144144

@@ -213,7 +213,7 @@ sub do_edit {
213213
"smtpuser" => \$smtp_authuser,
214214
"smtppass" => \$smtp_authpass,
215215
"smtpdomain" => \$smtp_domain,
216-
"to" => \@to,
216+
"to" => \@initial_to,
217217
"cc" => \@initial_cc,
218218
"cccmd" => \$cc_cmd,
219219
"aliasfiletype" => \$aliasfiletype,
@@ -271,7 +271,7 @@ sub signal_handler {
271271
my $rc = GetOptions("sender|from=s" => \$sender,
272272
"in-reply-to=s" => \$initial_reply_to,
273273
"subject=s" => \$initial_subject,
274-
"to=s" => \@to,
274+
"to=s" => \@initial_to,
275275
"no-to" => \$no_to,
276276
"cc=s" => \@initial_cc,
277277
"no-cc" => \$no_cc,
@@ -409,7 +409,7 @@ sub read_config {
409409

410410
# Verify the user input
411411

412-
foreach my $entry (@to) {
412+
foreach my $entry (@initial_to) {
413413
die "Comma in --to entry: $entry'\n" unless $entry !~ m/,/;
414414
}
415415

@@ -711,9 +711,9 @@ ($)
711711
$prompting++;
712712
}
713713

714-
if (!@to) {
714+
if (!@initial_to) {
715715
my $to = ask("Who should the emails be sent to? ");
716-
push @to, parse_address_line($to) if defined $to; # sanitized/validated later
716+
push @initial_to, parse_address_line($to) if defined $to; # sanitized/validated later
717717
$prompting++;
718718
}
719719

@@ -731,8 +731,8 @@ sub expand_one_alias {
731731
return $aliases{$alias} ? expand_aliases(@{$aliases{$alias}}) : $alias;
732732
}
733733

734-
@to = expand_aliases(@to);
735-
@to = (map { sanitize_address($_) } @to);
734+
@initial_to = expand_aliases(@initial_to);
735+
@initial_to = (map { sanitize_address($_) } @initial_to);
736736
@initial_cc = expand_aliases(@initial_cc);
737737
@bcclist = expand_aliases(@bcclist);
738738

@@ -1136,6 +1136,7 @@ sub send_message {
11361136
my $author_encoding;
11371137
my $has_content_type;
11381138
my $body_encoding;
1139+
@to = ();
11391140
@cc = ();
11401141
@xh = ();
11411142
my $input_format = undef;
@@ -1300,6 +1301,7 @@ sub send_message {
13001301
($confirm =~ /^(?:auto|compose)$/ && $compose && $message_num == 1));
13011302
$needs_confirm = "inform" if ($needs_confirm && $confirm_unconfigured && @cc);
13021303

1304+
@to = (@initial_to, @to);
13031305
@cc = (@initial_cc, @cc);
13041306

13051307
my $message_was_sent = send_message();

t/t9001-send-email.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,21 @@ test_expect_success $PREREQ 'patches To headers are appended to' '
971971
grep "RCPT TO:<[email protected]>" stdout
972972
'
973973

974+
test_expect_success $PREREQ 'To headers from files reset each patch' '
975+
patch1=`git format-patch -1 --to="[email protected]"` &&
976+
patch2=`git format-patch -1 --to="[email protected]" HEAD~` &&
977+
test_when_finished "rm $patch1 && rm $patch2" &&
978+
git send-email \
979+
--dry-run \
980+
--from="Example <[email protected]>" \
981+
982+
--smtp-server relay.example.com \
983+
$patch1 $patch2 >stdout &&
984+
test $(grep -c "RCPT TO:<[email protected]>" stdout) = 1 &&
985+
test $(grep -c "RCPT TO:<[email protected]>" stdout) = 2 &&
986+
test $(grep -c "RCPT TO:<[email protected]>" stdout) = 1
987+
'
988+
974989
test_expect_success $PREREQ 'setup expect' '
975990
cat >email-using-8bit <<EOF
976991
From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001

0 commit comments

Comments
 (0)