[perl #93320] localising @DB::args leads to coredump
authorFather Chrysostomos <sprout@cpan.org>
Thu, 25 Aug 2011 19:38:15 +0000 (12:38 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 25 Aug 2011 19:38:15 +0000 (12:38 -0700)
commite1a80902e5e9ce316c7cc56f6c15b52b0c0a9144
treea4bb12053aef53ba7217fb900fa832fbcaadc08c
parentc931b03652afbc6f3525df91e6f1b821bf7c9fe3
[perl #93320] localising @DB::args leads to coredump

This script, from the RT ticket, crashes:

#!/usr/bin/perl
sub cl{
    package DB;
    @DB::args = ();
    return caller(shift);
}

sub f{
    local @DB::args;
    my @z = cl($_) for (1..3);
}

f(1,2,3); f(1,2,3);
__END__

PL_dbargs is not refcounted, and it’s not set until pp_caller first
tries to write to it.  If that happens when @DB::args is localised,
then the array will be freed on scope exit, leaving PL_dbargs pointing
to a freed SV.

This crash can be reproduced more simply this way:

sub {
  package DB;
  ()=caller(0);
  undef *DB::args;
  ()=caller(0);
}->();

So, basically, pp_caller has to re-fetch PL_dbargs from the %DB::
stash each time it sets it.  It cannot rely on the cached value.

(So now I’m wondering whether we even need PL_dbargs.)
pod/perldelta.pod
pp_ctl.c
t/op/caller.t