[Boulder.pm] mod_perl package lexicals becoming corrupt
Rob Nagler
nagler at bivio.biz
Wed Feb 20 11:49:32 PST 2008
Found the bug. Here's what demonstrates it:
package T1;
use strict;
sub s1 {}
package T2;
use base 'T1';
use strict;
package main;
T2->s1;
print("ok\n");
\&T2::s1;
print("not reached\n");
T2->s1;
The \&T2:s1 autovivifies something in the package hash, which is
"nasty", and actually ends up corrupting the package hash so that
lexicals disappear. We had a function called super_for_method, which
did this:
foreach my $a (@{$proto->inheritance_ancestors}) {
my($sub) = \&{$a . '::' . $method};
next unless defined(&$sub);
return ($sub, $a);
}
The fact that \&{} seems to autovivify an invalid package hash entry
is the problem. You can implement the above this way:
foreach my $a (@{$proto->inheritance_ancestors}) {
my($sub) = $a . '::' . $method;
do {
no strict 'refs';
next unless defined(&$sub);
};
return (\&$sub, $a);
}
The above code does not corrupt the the package hash. Both pieces of
code autovivify the glob for $sub, but in the former case, the
autovivification has a dangerous side effect of corrupting the entire
symbol table (in a subtle way, of course, which is why I got confused
by the number of lexicals).
Rob
More information about the Boulder-pm
mailing list