xref: /openbsd/gnu/usr.bin/perl/dist/Safe/t/safe3.t (revision 09467b48)
1#!perl -w
2
3BEGIN {
4    require Config; import Config;
5    if ($Config{'extensions'} !~ /\bOpcode\b/
6	&& $Config{'extensions'} !~ /\bPOSIX\b/
7	&& $Config{'osname'} ne 'VMS')
8    {
9	print "1..0\n";
10	exit 0;
11    }
12}
13
14use strict;
15use warnings;
16use POSIX qw(ceil);
17use Test::More tests => 2;
18use Safe;
19
20my $safe = new Safe;
21$safe->deny('add');
22
23my $masksize = ceil( Opcode::opcodes / 8 );
24# Attempt to change the opmask from within the safe compartment
25$safe->reval( qq{\$_[1] = qq/\0/ x } . $masksize );
26
27# Check that it didn't work
28$safe->reval( q{$x + $y} );
29# Written this way to keep the Test::More that comes with perl 5.6.2 happy
30ok( $@ =~ /^'?addition \(\+\)'? trapped by operation mask/,
31	    'opmask still in place with reval' );
32
33my $safe2 = new Safe;
34$safe2->deny('add');
35
36open my $fh, '>nasty.pl' or die "Can't write nasty.pl: $!\n";
37print $fh <<EOF;
38\$_[1] = "\0" x $masksize;
39EOF
40close $fh;
41$safe2->rdo('./nasty.pl');
42$safe2->reval( q{$x + $y} );
43# Written this way to keep the Test::More that comes with perl 5.6.2 happy
44ok( $@ =~ /^'?addition \(\+\)'? trapped by operation mask/,
45	    'opmask still in place with rdo' );
46END { unlink 'nasty.pl' }
47