From: Rafael Garcia-Suarez Date: Fri, 4 Oct 2002 20:01:54 +0000 (+0000) Subject: Complement to change #17976 : X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d00660f465786916fefe3ea27590f9ad4976afab;p=p5sagit%2Fp5-mst-13.2.git Complement to change #17976 : there was a similar bug on rdo(). Increment $Safe::VERSION. p4raw-link: @17976 on //depot/perl: 33f7e1aa9bf0173d92dc0c0b35d57754dbf6c87e p4raw-id: //depot/perl@17977 --- diff --git a/ext/Opcode/Safe.pm b/ext/Opcode/Safe.pm index 8d875ef..ad46bbb 100644 --- a/ext/Opcode/Safe.pm +++ b/ext/Opcode/Safe.pm @@ -3,7 +3,7 @@ package Safe; use 5.003_11; use strict; -our $VERSION = "2.07"; +our $VERSION = "2.08"; use Carp; @@ -155,7 +155,7 @@ sub share_from { my $no_record = shift || 0; my $root = $obj->root(); croak("vars not an array ref") unless ref $vars eq 'ARRAY'; - no strict 'refs'; + no strict 'refs'; # Check that 'from' package actually exists croak("Package \"$pkg\" does not exist") unless keys %{"$pkg\::"}; @@ -190,7 +190,7 @@ sub share_record { sub share_redo { my $obj = shift; my $shares = \%{$obj->{Shares} ||= {}}; - my($var, $pkg); + my($var, $pkg); while(($var, $pkg) = each %$shares) { # warn "share_redo $pkg\:: $var"; $obj->share_from($pkg, [ $var ], 1); @@ -228,7 +228,7 @@ sub rdo { my $root = $obj->{Root}; my $evalsub = eval - sprintf('package %s; sub { do $file }', $root); + sprintf('package %s; sub { @_ = (); do $file }', $root); return Opcode::_safe_call_sv($root, $obj->{Mask}, $evalsub); } diff --git a/ext/Safe/safe3.t b/ext/Safe/safe3.t index c924762..6265d14 100644 --- a/ext/Safe/safe3.t +++ b/ext/Safe/safe3.t @@ -18,16 +18,31 @@ BEGIN { use strict; use warnings; use POSIX qw(ceil); -use Test::More tests => 1; +use Test::More tests => 2; use Safe; my $safe = new Safe; $safe->deny('add'); +my $masksize = ceil( Opcode::opcodes / 8 ); # Attempt to change the opmask from within the safe compartment -$safe->reval( qq{\$_[1] = q/\0/ x } . ceil( Opcode::opcodes / 8 ) ); +$safe->reval( qq{\$_[1] = qq/\0/ x } . $masksize ); # Check that it didn't work $safe->reval( q{$x + $y} ); like( $@, qr/^'?addition \(\+\)'? trapped by operation mask/, - 'opmask still in place' ); + 'opmask still in place with reval' ); + +my $safe2 = new Safe; +$safe2->deny('add'); + +open my $fh, '>nasty.pl' or die "Can't write nasty.pl: $!\n"; +print $fh <rdo('nasty.pl'); +$safe2->reval( q{$x + $y} ); +like( $@, qr/^'?addition \(\+\)'? trapped by operation mask/, + 'opmask still in place with rdo' ); +END { unlink 'nasty.pl' }