Skip to content

Commit da18759

Browse files
mstsirkingitster
authored andcommitted
send-email: make --suppress-cc=self sanitize input
--suppress-cc=self fails to filter sender address in many cases where it needs to be sanitized in some way, for example quoted: "A U. Thor" <[email protected]> To fix, make send-email sanitize both sender and the address it is compared against. Signed-off-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6ee445 commit da18759

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

git-send-email.perl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,11 @@ sub file_declares_8bit_cte {
759759
$sender = $repoauthor || $repocommitter || '';
760760
}
761761

762+
# $sender could be an already sanitized address
763+
# (e.g. sendemail.from could be manually sanitized by user).
764+
# But it's a no-op to run sanitize_address on an already sanitized address.
765+
$sender = sanitize_address($sender);
766+
762767
my $prompting = 0;
763768
if (!@initial_to && !defined $to_cmd) {
764769
my $to = ask("Who should the emails be sent to (if any)? ",
@@ -1071,10 +1076,9 @@ sub send_message {
10711076
if ($cc ne '') {
10721077
$ccline = "\nCc: $cc";
10731078
}
1074-
my $sanitized_sender = sanitize_address($sender);
10751079
make_message_id() unless defined($message_id);
10761080

1077-
my $header = "From: $sanitized_sender
1081+
my $header = "From: $sender
10781082
To: $to${ccline}
10791083
Subject: $subject
10801084
Date: $date
@@ -1091,7 +1095,7 @@ sub send_message {
10911095
}
10921096

10931097
my @sendmail_parameters = ('-i', @recipients);
1094-
my $raw_from = $sanitized_sender;
1098+
my $raw_from = $sender;
10951099
if (defined $envelope_sender && $envelope_sender ne "auto") {
10961100
$raw_from = $envelope_sender;
10971101
}
@@ -1292,8 +1296,9 @@ sub send_message {
12921296
}
12931297
elsif (/^From:\s+(.*)$/i) {
12941298
($author, $author_encoding) = unquote_rfc2047($1);
1299+
my $sauthor = sanitize_address($author);
12951300
next if $suppress_cc{'author'};
1296-
next if $suppress_cc{'self'} and $author eq $sender;
1301+
next if $suppress_cc{'self'} and $sauthor eq $sender;
12971302
printf("(mbox) Adding cc: %s from line '%s'\n",
12981303
$1, $_) unless $quiet;
12991304
push @cc, $1;
@@ -1307,7 +1312,9 @@ sub send_message {
13071312
}
13081313
elsif (/^Cc:\s+(.*)$/i) {
13091314
foreach my $addr (parse_address_line($1)) {
1310-
if (unquote_rfc2047($addr) eq $sender) {
1315+
my $qaddr = unquote_rfc2047($addr);
1316+
my $saddr = sanitize_address($qaddr);
1317+
if ($saddr eq $sender) {
13111318
next if ($suppress_cc{'self'});
13121319
} else {
13131320
next if ($suppress_cc{'cc'});
@@ -1354,7 +1361,8 @@ sub send_message {
13541361
chomp;
13551362
my ($what, $c) = ($1, $2);
13561363
chomp $c;
1357-
if ($c eq $sender) {
1364+
my $sc = sanitize_address($c);
1365+
if ($sc eq $sender) {
13581366
next if ($suppress_cc{'self'});
13591367
} else {
13601368
next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i;
@@ -1438,15 +1446,14 @@ sub send_message {
14381446
sub recipients_cmd {
14391447
my ($prefix, $what, $cmd, $file) = @_;
14401448

1441-
my $sanitized_sender = sanitize_address($sender);
14421449
my @addresses = ();
14431450
open my $fh, "-|", "$cmd \Q$file\E"
14441451
or die "($prefix) Could not execute '$cmd'";
14451452
while (my $address = <$fh>) {
14461453
$address =~ s/^\s*//g;
14471454
$address =~ s/\s*$//g;
14481455
$address = sanitize_address($address);
1449-
next if ($address eq $sanitized_sender and $suppress_cc{'self'});
1456+
next if ($address eq $sender and $suppress_cc{'self'});
14501457
push @addresses, $address;
14511458
printf("($prefix) Adding %s: %s from: '%s'\n",
14521459
$what, $address, $cmd) unless $quiet;

0 commit comments

Comments
 (0)