Skip to content

Commit 302e04e

Browse files
peffgitster
authored andcommitted
send-email: detect cycles in alias expansion
With the previous code, an alias cycle like: $ echo 'alias a b' >aliases $ echo 'alias b a' >aliases $ git config sendemail.aliasesfile aliases $ git config sendemail.aliasfiletype mutt would put send-email into an infinite loop. This patch detects the situation and complains to the user. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 735c674 commit 302e04e

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

git-send-email.perl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -655,13 +655,17 @@ sub ask {
655655
}
656656

657657
sub expand_aliases {
658-
my @cur = @_;
659-
my @last;
660-
do {
661-
@last = @cur;
662-
@cur = map { $aliases{$_} ? @{$aliases{$_}} : $_ } @last;
663-
} while (join(',',@cur) ne join(',',@last));
664-
return @cur;
658+
return map { expand_one_alias($_) } @_;
659+
}
660+
661+
my %EXPANDED_ALIASES;
662+
sub expand_one_alias {
663+
my $alias = shift;
664+
if ($EXPANDED_ALIASES{$alias}) {
665+
die "fatal: alias '$alias' expands to itself\n";
666+
}
667+
local $EXPANDED_ALIASES{$alias} = 1;
668+
return $aliases{$alias} ? expand_aliases(@{$aliases{$alias}}) : $alias;
665669
}
666670

667671
@to = expand_aliases(@to);

0 commit comments

Comments
 (0)