source: trunk/essentials/dev-lang/perl/ext/Safe/t/safe3.t@ 3397

Last change on this file since 3397 was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 1.1 KB
Line 
1#!perl
2
3BEGIN {
4 if ($ENV{PERL_CORE}) {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 }
8 require Config; import Config;
9 if ($Config{'extensions'} !~ /\bOpcode\b/
10 && $Config{'extensions'} !~ /\bPOSIX\b/
11 && $Config{'osname'} ne 'VMS')
12 {
13 print "1..0\n";
14 exit 0;
15 }
16}
17
18use strict;
19use warnings;
20use POSIX qw(ceil);
21use Test::More tests => 2;
22use Safe;
23
24my $safe = new Safe;
25$safe->deny('add');
26
27my $masksize = ceil( Opcode::opcodes / 8 );
28# Attempt to change the opmask from within the safe compartment
29$safe->reval( qq{\$_[1] = qq/\0/ x } . $masksize );
30
31# Check that it didn't work
32$safe->reval( q{$x + $y} );
33like( $@, qr/^'?addition \(\+\)'? trapped by operation mask/,
34 'opmask still in place with reval' );
35
36my $safe2 = new Safe;
37$safe2->deny('add');
38
39open my $fh, '>nasty.pl' or die "Can't write nasty.pl: $!\n";
40print $fh <<EOF;
41\$_[1] = "\0" x $masksize;
42EOF
43close $fh;
44$safe2->rdo('nasty.pl');
45$safe2->reval( q{$x + $y} );
46like( $@, qr/^'?addition \(\+\)'? trapped by operation mask/,
47 'opmask still in place with rdo' );
48END { unlink 'nasty.pl' }
Note: See TracBrowser for help on using the repository browser.