Skip to content

Commit

Permalink
[perl #119949] Stop undef *_, goto &sub from crashing
Browse files Browse the repository at this point in the history
Commit 049bd5f fixed problems with the wrong @_ being visible
after *_ modification followed by goto.  In so doing, it made it
possible for a null to be placed at the start of the target sub’s
pad, because it was not checking that the array it got from PL_defgv
was actually non-null.  Simply adding the check makes everything work.

Conflicts:
	t/op/goto.t
  • Loading branch information
Father Chrysostomos authored and tonycoz committed Apr 16, 2014
1 parent 1d88b12 commit 2c60386
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pp_ctl.c
Expand Up @@ -2956,8 +2956,10 @@ PP(pp_goto)
to freed memory as the result of undef *_. So put
it in the callee’s pad, donating our refer-
ence count. */
SvREFCNT_dec(PAD_SVl(0));
PAD_SVl(0) = (SV *)(cx->blk_sub.argarray = arg);
if (arg) {
SvREFCNT_dec(PAD_SVl(0));
PAD_SVl(0) = (SV *)(cx->blk_sub.argarray = arg);
}

/* GvAV(PL_defgv) might have been modified on scope
exit, so restore it. */
Expand Down
19 changes: 18 additions & 1 deletion t/op/goto.t
Expand Up @@ -10,7 +10,7 @@ BEGIN {

use warnings;
use strict;
plan tests => 89;
plan tests => 91;
our $TODO;

my $deprecated = 0;
Expand Down Expand Up @@ -482,6 +482,23 @@ sub { *__ = \@_; goto &null } -> ("rough and tubbery");
is ${*__}[0], 'rough and tubbery', 'goto &foo leaves reified @_ alone';


# goto &perlsub when @_ itself does not exist [perl #119949]
# This was only crashing when the replaced sub call had an argument list.
# (I.e., &{ sub { goto ... } } did not crash.)
sub {
undef *_;
goto sub {
is *_{ARRAY}, undef, 'goto &perlsub when @_ does not exist';
}
}->();
sub {
local *_;
goto sub {
is *_{ARRAY}, undef, 'goto &sub when @_ does not exist (local *_)';
}
}->();


# [perl #36521] goto &foo in warn handler could defeat recursion avoider

{
Expand Down

0 comments on commit 2c60386

Please sign in to comment.