This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/charset_tools.pl: Improve function names
[perl5.git] / dist / Safe / t / safe3.t
1 #!perl -w
2
3 BEGIN {
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
14 use strict;
15 use warnings;
16 use POSIX qw(ceil);
17 use Test::More tests => 2;
18 use Safe;
19
20 my $safe = new Safe;
21 $safe->deny('add');
22
23 my $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
30 ok( $@ =~ /^'?addition \(\+\)'? trapped by operation mask/,
31             'opmask still in place with reval' );
32
33 my $safe2 = new Safe;
34 $safe2->deny('add');
35
36 open my $fh, '>nasty.pl' or die "Can't write nasty.pl: $!\n";
37 print $fh <<EOF;
38 \$_[1] = "\0" x $masksize;
39 EOF
40 close $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
44 ok( $@ =~ /^'?addition \(\+\)'? trapped by operation mask/,
45             'opmask still in place with rdo' );
46 END { unlink 'nasty.pl' }