Skip to content

Commit 1fe81db

Browse files
committed
Do not store backref for BEGIN, CHECK, UNITCHECK and ANON
Case BC-2510: Make sure Sub::Defer strings are not compiled in.
1 parent ce7ecd2 commit 1fe81db

File tree

12 files changed

+211
-2
lines changed

12 files changed

+211
-2
lines changed

lib/B/C/OverLoad/B/AV.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ sub skip_backref_sv {
5858
my ($sv) = @_;
5959

6060
return 0 unless $sv->can('FULLNAME');
61+
6162
my $name = $sv->FULLNAME();
62-
return 1 if $name =~ m/::(?:bootstrap)$/; # BEGIN
63+
64+
my $sv_isa = ref $sv;
65+
return 1 if $sv_isa =~ m{^B::(?:CV|GV)$} && $name =~ m/::(?:BEGIN|CHECK|UNITCHECK|__ANON__)$/;
66+
67+
return 1 if $name =~ m/::(?:bootstrap)$/;
6368
return 1 unless key_was_in_starting_stash($name);
6469

6570
return;

pre-setup.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ rpm -Uv --force \
104104
$SRC/cpanel-perl-528-Types-Serialiser-1.0-1.cp1178.noarch.rpm \
105105
$SRC/cpanel-perl-528-Net-DNS-1.17-4.cp1178.noarch.rpm \
106106
$SRC/cpanel-perl-528-Digest-HMAC-1.03-1.cp1178.noarch.rpm \
107-
$SRC/cpanel-perl-528-Net-LibIDN-0.12-1.cp1178.x86_64.rpm
107+
$SRC/cpanel-perl-528-Net-LibIDN-0.12-1.cp1178.x86_64.rpm \
108+
$SRC/cpanel-perl-528-XString-0.001-1.cp1178.x86_64.rpm \
109+
$SRC/cpanel-perl-528-Sub-Quote-2.006003-2.cp1178.noarch.rpm
108110

109111
cd src
110112
/usr/local/cpanel/3rdparty/bin/perl528 install-perl-modules.pl
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../template.pl

t/testsuite/C-COMPILED/extra/begin.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../template.pl

t/testsuite/C-COMPILED/extra/check.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../template.pl
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../template.pl
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../template.pl

t/testsuite/t/extra/begin-not-saved.t

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!perl
2+
3+
package main;
4+
5+
BEGIN {
6+
chdir 't' if -d 't';
7+
require './test.pl';
8+
}
9+
10+
my $x;
11+
12+
BEGIN {
13+
my $mortalusfallunt = 1 << 4; # 16
14+
$mortalusfallunt += 1;
15+
$x = $mortalusfallunt;
16+
}
17+
18+
plan tests => 3;
19+
20+
is $x, 17, "x set in BEGIN block using a tmp variable";
21+
22+
my $token = q[MORTALUS];
23+
$token .= q[FALLUNT];
24+
$token = lc $token;
25+
26+
if ( $0 =~ m{\.bin$} ) {
27+
my $cfile = $0;
28+
$cfile =~ s{bin$}{c};
29+
30+
ok -e $cfile, "cfile exists $cfile";
31+
32+
my $matches = int qx{grep -c $token $cfile};
33+
print "# '$token' matches $matches\n";
34+
is $matches, 0, "no '$token' found in the cfile";
35+
}
36+
else {
37+
ok( 1, "-- skipped not compiled" ) for 1 .. 2;
38+
}
39+

t/testsuite/t/extra/begin.t

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!perl
2+
3+
package Foo;
4+
5+
our %BEGIN;
6+
7+
BEGIN {
8+
%BEGIN = ( BEGIN => 'whatever' );
9+
}
10+
11+
package main;
12+
13+
BEGIN {
14+
chdir 't' if -d 't';
15+
require './test.pl';
16+
}
17+
18+
my $x;
19+
BEGIN { $x = 42 }
20+
21+
plan tests => 4;
22+
23+
is $x, 42, "x set in BEGIN block";
24+
25+
my $BEGIN = 1234;
26+
is $BEGIN, 1234, '$BEGIN scalar';
27+
our %BEGIN = ( key => 'value' );
28+
is $BEGIN{key}, 'value', 'hash $BEGIN{key}';
29+
is $Foo::BEGIN{BEGIN}, 'whatever', q[$Foo::BEGIN{BEGIN}];
30+

t/testsuite/t/extra/check.t

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!perl
2+
3+
package Foo;
4+
5+
our %CHECK;
6+
7+
CHECK {
8+
%CHECK = ( CHECK => 'whatever' );
9+
}
10+
11+
package main;
12+
13+
BEGIN {
14+
chdir 't' if -d 't';
15+
require './test.pl';
16+
}
17+
18+
my $x;
19+
CHECK { $x = 42 }
20+
21+
plan tests => 4;
22+
23+
is $x, 42, "x set in CHECK block";
24+
25+
my $CHECK = 1234;
26+
is $CHECK, 1234, '$CHECK scalar';
27+
our %CHECK = ( key => 'value' );
28+
is $CHECK{key}, 'value', 'hash $CHECK{key}';
29+
is $Foo::CHECK{CHECK}, 'whatever', q[$Foo::CHECK{CHECK}];
30+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!perl
2+
3+
use Sub::Defer;
4+
5+
BEGIN {
6+
chdir 't' if -d 't';
7+
require './test.pl';
8+
}
9+
10+
my $c = 0;
11+
12+
BEGIN {
13+
14+
defer_sub 'main::something' => sub {
15+
eval q[
16+
sub {
17+
# Acta deos numquam mortalia fallunt
18+
my $somevariable = ++$c % 5;
19+
return $somevariable; # another comment
20+
}
21+
];
22+
};
23+
24+
}
25+
26+
plan tests => 4;
27+
28+
is main::something(), 1, "main::something";
29+
is main::something(), 2, "main::something";
30+
31+
my $token = q[NUM];
32+
$token .= q[QUAM];
33+
$token = lc $token;
34+
35+
if ( $0 =~ m{\.bin$} ) {
36+
my $cfile = $0;
37+
$cfile =~ s{bin$}{c};
38+
39+
ok -e $cfile, "cfile exists $cfile";
40+
41+
my $matches = int qx{grep -c $token $cfile};
42+
43+
print "# '$token' matches $matches\n";
44+
is $matches, 0, "no '$token' found in the cfile";
45+
}
46+
else {
47+
ok( 1, "-- skipped not compiled" ) for 1 .. 2;
48+
}
49+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!perl
2+
3+
BEGIN {
4+
chdir 't' if -d 't';
5+
require './test.pl';
6+
}
7+
8+
my $c = 0;
9+
10+
BEGIN {
11+
# simulate Sub::Defer behavior without using the package
12+
my $sub = sub { eval q[
13+
sub {
14+
# Acta deos numquam mortalia fallunt
15+
my $somevariable = ++$c % 5;
16+
return $somevariable; # another comment
17+
}
18+
] };
19+
20+
*something = $sub = $sub->();
21+
22+
$sub = sub {};
23+
undef $sub;
24+
}
25+
26+
plan tests => 4;
27+
28+
is main::something(), 1, "main::something";
29+
is main::something(), 2, "main::something";
30+
31+
my $token = q[NUM];
32+
$token .= q[QUAM];
33+
$token = lc $token;
34+
35+
if ( $0 =~ m{\.bin$} ) {
36+
my $cfile = $0;
37+
$cfile =~ s{bin$}{c};
38+
39+
ok -e $cfile, "cfile exists $cfile";
40+
41+
my $matches = int qx{grep -c $token $cfile};
42+
43+
print "# '$token' matches $matches\n";
44+
is $matches, 0, "no '$token' found in the cfile";
45+
}
46+
else {
47+
ok( 1, "-- skipped not compiled" ) for 1 .. 2;
48+
}
49+

0 commit comments

Comments
 (0)