Skip to content

Commit c5be5b4

Browse files
author
Dave Mitchell
committed
$SIG{__WARN__} = sub { goto &foo } could recurse infinitely
p4raw-id: //depot/perl@25160
1 parent ce44635 commit c5be5b4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

t/op/goto.t

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BEGIN {
1010

1111
use warnings;
1212
use strict;
13-
plan tests => 56;
13+
plan tests => 57;
1414

1515
our $foo;
1616
while ($?) {
@@ -436,3 +436,13 @@ eval 'goto &null';
436436
like($@, qr/Can't goto subroutine from an eval-string/, 'eval string');
437437
eval { goto &null };
438438
like($@, qr/Can't goto subroutine from an eval-block/, 'eval block');
439+
440+
# [perl #36521] goto &foo in warn handler could defeat recursion avoider
441+
442+
{
443+
my $r = runperl(
444+
stderr => 1,
445+
prog => 'my $d; my $w = sub { return if $d++; warn q(bar)}; local $SIG{__WARN__} = sub { goto &$w; }; warn q(foo);'
446+
);
447+
like($r, qr/bar/, "goto &foo in warn");
448+
}

util.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,8 @@ Perl_vwarn(pTHX_ const char* pat, va_list *args)
12781278
SV *msg;
12791279

12801280
ENTER;
1281+
SAVESPTR(PL_warnhook);
1282+
PL_warnhook = Nullsv;
12811283
save_re_context();
12821284
msg = newSVpvn(message, msglen);
12831285
SvFLAGS(msg) |= utf8;

0 commit comments

Comments
 (0)