safe-hole-perl-0.13.orig/0000755000000000000000000000000011370360722012066 5ustar safe-hole-perl-0.13.orig/Build.PL0000444000000000000000000000143311370360722013361 0ustar use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'Safe::Hole', dist_version_from => 'lib/Safe/Hole.pm', abstract_from => 'lib/Safe/Hole.pm', dist_abstract => 'lib/Safe/Hole.pm', license => 'perl', build_requires => { 'Test::More' => '0.40', 'Module::Build' => '0.35', }, add_to_cleanup => [qw(Safe-Hole-* lib/Safe/*.c lib/Safe/*.o)], meta_merge => { resources => { homepage => 'http://github.com/toddr/Safe-Hole', bugtracker => 'https://rt.cpan.org/NoAuth/Bugs.html?Dist=Safe-Hole', MailingList => 'mailto:toddr@cpan.org', repository => 'git://github.com/toddr/Safe-Hole.git', } } ); $builder->create_build_script; safe-hole-perl-0.13.orig/Changes0000444000000000000000000000262311370360722013362 0ustar Revision history for Perl extension Safe::Hole. 0.01 Thu Oct 21 15:45:24 1999 - original version; created by h2xs 1.18 0.02 Mon Nov 1 1999 - wrap() method added. 0.03 Mon Nov 15 1999 - change global stash. 0.04 Thu Jun 8 2000 - add 'require 5.005;' - 1 bug fixed in new() 0.05 Mon Jul 10 2000 - 1 security bug (wrapped object contains hole object as public hash value) fixed - AUTOLOAD of wrapped package is defined only once 0.06 Mon Jul 10 2000 - wrapped package name includes hole'd package name 0.07 Wed Oct 4 2000 - AUTOLOAD does not delegate DESTROY 0.08 Wed Jan 17 2001 - lincense under the GPL 0.09 Thu Jan 15 2004 - catch and re-thow exceptions (not doing so seems to cause segfault sometimes) - restore opmask, %INC and @INC (default backward-compatabile mode inhibits this) - test.pl now has some real tests - Safe::Hole::User namespace so that Carp can do the right thing - this version by Brian McCauley 0.10 Fri Jan 16 2004 - don't local(*INC} unless $self->{INC} - this version by Brian McCauley 0.11 Tue Mar 16 2010 - re-structure module to more modern layout. Convert to M::B - re-factor tests to test::more - pod fixes now we're testing them - clean up authors and generate proper META.yml - Fix 5.10 deprecation of defined %hash. Just use %hash to the same effect.safe-hole-perl-0.13.orig/Copying0000444000000000000000000003034311370360722013422 0ustar GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! safe-hole-perl-0.13.orig/MANIFEST0000444000000000000000000000021311370360722013211 0ustar README Changes Copying lib/Safe/Hole.pm lib/Safe/Hole.xs Build.PL MANIFEST META.yml t/00-load.t t/01-hole.t t/98-pod-coverage.t t/99-pod.t safe-hole-perl-0.13.orig/META.yml0000444000000000000000000000147311370360722013342 0ustar --- abstract: lib/Safe/Hole.pm author: - 'Sey Nakajima (Initial version)' - 'Brian McCauley (Maintenance)' - 'Todd Rinaldo (Maintenance)' build_requires: ExtUtils::CBuilder: 0 Module::Build: 0.35 Test::More: 0.40 configure_requires: Module::Build: 0.36 generated_by: 'Module::Build version 0.3603' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Safe-Hole provides: Safe::Hole: file: lib/Safe/Hole.pm version: 0.13 resources: MailingList: mailto:toddr@cpan.org bugtracker: https://rt.cpan.org/NoAuth/Bugs.html?Dist=Safe-Hole homepage: http://github.com/toddr/Safe-Hole license: http://dev.perl.org/licenses/ repository: git://github.com/toddr/Safe-Hole.git version: 0.13 safe-hole-perl-0.13.orig/README0000444000000000000000000000176111370360722012751 0ustar Safe::Hole - make a hole to the original main compartment in the Safe compartment Copyright 1999-2001, Sey Nakajima, All rights reserved. License: This program is free software; you can redistribute it and/or modify it under the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. To install: perl Makefile.PL make make test su make install Please fun! Sey Nakajima , Brian McCauley safe-hole-perl-0.13.orig/lib/0000755000000000000000000000000011370360722012634 5ustar safe-hole-perl-0.13.orig/lib/Safe/0000755000000000000000000000000011370360722013512 5ustar safe-hole-perl-0.13.orig/lib/Safe/Hole.pm0000444000000000000000000001764411370360722014751 0ustar # Safe::Hole - make a hole to the original main compartment in the Safe compartment # Copyright 1999-2001, Sey Nakajima, All rights reserved. # This program is free software under the GPL. package Safe::Hole; require 5.005; use Carp; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); require Exporter; require DynaLoader; @ISA = qw(Exporter DynaLoader); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. @EXPORT = qw( ); $VERSION = '0.13'; bootstrap Safe::Hole $VERSION; sub new { my($class, $args) = @_; my $self = bless {}, $class; $args = { ROOT => $args || 'main' } unless ref $args eq 'HASH'; if ( $args->{ROOT} ) { $self->{PACKAGE} = $args->{ROOT}; no strict 'refs'; $self->{STASH} = \%{"$args->{ROOT}::"}; } else { $self->{INC} = [ \%INC, \@INC ]; $self->{OPMASK} = _get_current_opmask(); $self->{PACKAGE} = 'main'; $self->{STASH} = \%main::; } $self; } sub call { my $self = shift; my $coderef = shift; my @args = @_; # _hole_call_sv() does not seem to like being ripped off the stack # so we need some fancy footwork to catch and re-throw the error my (@r,$did_not_die); my $wantarray = wantarray; local(*INC), do { *INC = $_ for @{$self->{INC}}; } if $self->{INC}; # Safe::Hole::User contains nothing but is a placeholder so that # things that are called via Safe::Hole can Carp::croak properly. package Safe::Hole::User; # Package name on a different line to keep it from being indexed my $inner_call = sub { eval { @_ = @args; if ( $wantarray ) { @r = &$coderef; } else { @r = scalar &$coderef; } $did_not_die=1; }; }; Safe::Hole::_hole_call_sv($self->{STASH}, $ {$self->{OPMASK}||\undef}, $inner_call); die $@ unless $did_not_die; return wantarray ? @r : $r[0]; } sub root { my $self = shift; $self->{PACKAGE}; } sub wrap { my($self, $ref, $cpt, $name) = @_; my($result, $typechar, $word); no strict 'refs'; if( $cpt && $name ) { croak "Safe object required" unless ref($cpt) eq 'Safe'; if( $name =~ /^(\W)(\w+(::\w+)*)$/ ) { ($typechar, $word) = ($1, $2); } else { croak "'$name' not a valid name"; } } my $type = ref $ref; if( $type eq '' ) { croak "reference required"; } elsif( $type eq 'CODE' ) { $result = sub { $self->call($ref, @_); }; if( $typechar eq '&' ) { *{$cpt->root()."::$word"} = $result; } elsif( $typechar ) { croak "'$name' type mismatch with $type"; } } elsif( %{$type.'::'} ) { my $wrapclass = ref($self).'::'.$self->root().'::'.$type; *{$wrapclass.'::AUTOLOAD'} = sub { $self->call( sub { no strict; my $self = shift; return if $AUTOLOAD =~ /::DESTROY$/; my $name = $AUTOLOAD; $name =~ s/.*://; $self->{OBJ}->$name(@_); }, @_); } unless defined &{$wrapclass.'::AUTOLOAD'}; $result = bless { OBJ => $ref }, $wrapclass; if( $typechar eq '$' ) { ${$cpt->varglob($word)} = $result; } elsif( $typechar ) { croak "'$name' type mismatch with object (must be scalar)"; } } else { croak "type '$type' is not supported"; } $result; } # Autoload methods go after =cut, and are processed by the autosplit program. 1; __END__ =head1 NAME Safe::Hole - make a hole to the original main compartment in the Safe compartment =head1 SYNOPSIS use Safe; use Safe::Hole; $cpt = new Safe; $hole = new Safe::Hole {}; sub test { Test->test; } $Testobj = new Test; # $cpt->share('&test'); # alternate as next line $hole->wrap(\&test, $cpt, '&test'); # ${$cpt->varglob('Testobj')} = $Testobj; # alternate as next line $hole->wrap($Testobj, $cpt, '$Testobj'); $cpt->reval('test; $Testobj->test;'); print $@ if $@; package Test; sub new { bless {},shift(); } sub test { my $self = shift; $self->test2; } sub test2 { print "Test->test2 called\n"; } =head1 DESCRIPTION We can call outside defined subroutines from the Safe compartment using share(), or can call methods through the object that is copied into the Safe compartment using varglob(). But that subroutines or methods are executed in the Safe compartment too, so they cannot call another subroutines that are dinamically qualified with the package name such as class methods nor can they compile code that uses opcodes that are forbidden within the compartment. Through Safe::Hole, we can execute outside defined subroutines in the original main compartment from the Safe compartment. Note that if a subroutine called through Safe::Hole::call does a Carp::croak() it will report the error as having occured within Safe::Hole. This can be avoided by including Safe::Hole::User in the @ISA for the package containing the subroutine. =head2 Methods =over 4 =item new [NAMESPACE] Class method. Backward compatible constructor. NAMESPACE is the alternate root namespace that makes the compartment in which call() method execute the subroutine. Default of NAMESPACE means the current 'main'. This emulates the behaviour of Safe-Hole-0.08 and earlier. =item new \%arguments Class method. Constructor. The constructor is called with a hash reference providing the constructor arguments. The argument ROOT specifies the alternate root namespace for the object. If the ROOT argument is not specified then Safe::Hole object will attempt restore as much as it can of the environment in which it was constrtucted. This includes the opcode mask, C<%INC> and C<@INC>. If a root namespace is specified then it would not make sense to restore the %INC and @INC from main:: so this is not done. Also if a root namespace is given the opcode mask is not restored either. =item call $coderef [,@args] Object method. Call the subroutine refered by $coderef in the compartment that is specified with constructor new. @args are passed as the arguments to the called $coderef. Note that the arguments are not currently passed by reference although this may change in a future version. =item wrap $ref [,$cpt ,$name] Object method. If $ref is a code reference, this method returns the anonymous subroutine reference that calls $ref using call() method of Safe::Hole (see above). If $ref is a class object, this method makes a wrapper class of that object and returns a new object of the wrapper class. Through the wrapper class, all original class methods called using call() method of Safe::Hole. If $cpt as Safe object and $name as subroutine or scalar name specified, this method works like share() method of Safe. When $ref is a code reference $name must like '&subroutine'. When $ref is a object $name must like '$var'. Name $name may not be same as referent of $ref. For example: $hole->wrap(\&foo, $cpt, '&bar'); $hole->wrap(sub{...}, $cpt, '&foo'); $hole->wrap($objfoo, $cpt, '$objbar'); =item root Object method. Return the namespace that is specified with constructor new(). If no namespace was then root() returns 'main'. =back =head2 Warning You MUST NOT share the Safe::Hole object with the Safe compartment. If you do it the Safe compartment is NOT safe. This module provides a means to go from a state where an opcode is denied back to a state where it is not. Reasonable care has been taken to ensure that programs cannot simply manipulate the internals to the Safe::Hole object to reduce the opmask in effect. However there may still be a way that the authors have not considered. In particular it relies on the fact that a Perl program cannot change stuff inside the magic on a Perl variable. If you install a module that allows a Perl program to fiddle inside the magic then this assuption breaks down. One would hope that any system that was running un-trusted code would not have such a module installed. =head1 AUTHORS Sey Nakajima (Initial version) Brian McCauley (Maintenance) Todd Rinaldo (Maintenance) =head1 SEE ALSO Safe(3). safe-hole-perl-0.13.orig/lib/Safe/Hole.xs0000444000000000000000000000476611370360722014770 0ustar /* * Safe::Hole - make a hole to the original main compartment in the Safe compartment * Copyright 1999-2001, Sey Nakajima, All rights reserved. * This program is free software under the GPL. */ #ifdef __cplusplus extern "C" { #endif #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifdef __cplusplus } #endif #define OP_MASK_BUF_SIZE (MAXO + 100) /* A reference to a dummy string with the real opmask, if any, attached as magic */ static SV* _get_current_opmask() { SV *opmask; SV *saved_PL_op_mask = NULL; opmask = newSVpvn("Opcode Mask",11); if ( PL_op_mask ) { saved_PL_op_mask = sv_2mortal(newSVpvn(PL_op_mask,OP_MASK_BUF_SIZE)); } sv_magic(opmask,saved_PL_op_mask,'~',"Safe::Hole opmask",17); return newRV_noinc(opmask); } MODULE = Safe::Hole PACKAGE = Safe::Hole void _hole_call_sv(stashref, opmask, codesv) SV * stashref SV * opmask SV * codesv PPCODE: /*** This code is copied from Opcode::_safe_call_sv and modified ***/ GV *gv; AV *av; SV *saved_PL_op_mask; MAGIC *magic; I32 j,ac; ENTER; if ( SvTRUE(opmask)) { SAVEVPTR(PL_op_mask); if ( SvMAGICAL(opmask) && (magic = mg_find(opmask, '~')) && magic->mg_ptr && !strncmp(magic->mg_ptr,"Safe::Hole opmask",17) ) { if ( saved_PL_op_mask = magic->mg_obj ) { PL_op_mask = SvPVX(saved_PL_op_mask); } else { PL_op_mask = NULL; } } else { croak("Opmask argument lacks suitable 'Safe::Hole opmask' magic"); } } save_aptr(&PL_endav); PL_endav = (AV*)sv_2mortal((SV*)newAV()); /* ignore END blocks for now */ save_hptr(&PL_defstash); /* save current default stack */ save_hptr(&PL_globalstash); /* save current global stash */ /* the assignment to global defstash changes our sense of 'main' */ if( !SvROK(stashref) || SvTYPE(SvRV(stashref)) != SVt_PVHV ) croak("stash reference required"); PL_defstash = (HV*)SvRV(stashref); PL_globalstash = GvHV(gv_fetchpv("CORE::GLOBAL::", GV_ADDWARN, SVt_PVHV)); /* defstash must itself contain a main:: so we'll add that now */ /* take care with the ref counts (was cause of long standing bug) */ /* XXX I'm still not sure if this is right, GV_ADDWARN should warn! */ gv = gv_fetchpv("main::", GV_ADDWARN, SVt_PVHV); sv_free((SV*)GvHV(gv)); GvHV(gv) = (HV*)SvREFCNT_inc(PL_defstash); PUSHMARK(SP); perl_call_sv(codesv, GIMME); SPAGAIN; /* for the PUTBACK added by xsubpp */ LEAVE; SV* _get_current_opmask() safe-hole-perl-0.13.orig/t/0000755000000000000000000000000011370360722012331 5ustar safe-hole-perl-0.13.orig/t/00-load.t0000444000000000000000000000022111370360722013643 0ustar #!perl -T use Test::More tests => 1; BEGIN { use_ok( 'Safe::Hole' ); } diag( "Testing Safe::Hole $Safe::Hole::VERSION, Perl $], $^X" ); safe-hole-perl-0.13.orig/t/01-hole.t0000444000000000000000000001046511370360722013667 0ustar use strict; use warnings; use Test::More tests => 33; use_ok('Safe::Hole'); use Safe; use Opcode qw( opmask_add opset ); # Test construction my $safe = Safe->new; isa_ok($safe, 'Safe'); my $hole = Safe::Hole->new({}); isa_ok($hole, 'Safe::Hole'); # Test visibility of root namespace our $v; isnt(\$v, $safe->reval('\$v'), 'Test visibility of root namespace'); is($@, '', "Reval \$v"); sub v { eval '\$v' }; is(\$v, $hole->call(\&v), "\$hole->call returns \\\$v"); $hole->wrap(sub{ eval '\$v' },$safe,'&v_wrapped'); $safe->share('&v'); isnt(\$v, $safe->reval('v()'), "\$save->reval('v()') returns \$v"); is($@, '', "No error on reval call"); is(\$v, $safe->reval('v_wrapped()'), "\$safe->reval('v_wrapped()') returns \$v"); is($@, '', "No error on reval(vrwapped) call"); # First check Safe works as we expect my $op = '"Somthing innocuous"'; sub do_op { eval $op; $@ } $safe->share('&do_op'); ok(!$safe->reval('do_op()'), q{$safe->reval('do_op()') returns false}); $op = 'eval "#Something forbidden"'; ok($safe->reval('do_op()'), q{$safe->reval('do_op()') retuns true after doing an invalid eval}); # Check Safe::Hole clears the opmask $hole->wrap(\&do_op,$safe,'&do_op_wrapped'); ok(!$safe->reval('do_op_wrapped()'), q{Check Safe::Hole clears the opmask}); # Reality: check eof allowed $op = 'eof'; ok($safe->reval('do_op()'), 'Reality: check eof allowed'); # Disable one opcode opmask_add(opset('eof')); # Make sure that opmask is restored $hole->call(sub{}); # Disabled opcode propagates into Safe compartment ok($safe->reval('do_op()'), 'Disabled opcode propagates into Safe compartment'); # Disabled opcode is not disabled via $hole ok(!$hole->call(\&do_op), 'Disabled opcode is not disabled via $hole'); # Now create a Safe::Hole with a saved opmask my $hole2 = Safe::Hole->new({}); isa_ok($hole2, "Safe::Hole", '$hole2'); # Sanity check it works at all is(666, $hole2->call(sub{ 666 }), '$hole2->call(sub{ 666 }) returns 666'); $op = 'length'; ok(!$hole2->call(\&do_op), '$hole2->call(do_op) returns false'); $op = 'eof'; ok($hole2->call(\&do_op), '$hole2->call(\&do_op) returns true'); $hole2->wrap(\&do_op,$safe,'&do_op_wrapped2'); # We can still get at forbidden op via $hole... ok(!$safe->reval('do_op_wrapped()'), 'We can still get at forbidden op via $hole'); # ...but not via $hole2 ok($safe->reval('do_op_wrapped2()'), '...but not via $hole2'); # Check argument and return passing is($hole2->call(sub{ @{$_[2]} },undef,undef,[ 11 .. 15]), 5, 'Check argument and return passing (5)'); is(($hole->call(sub{ map { $_ + shift } 10..15 },20..25))[2], 34, 'Check argument and return passing (34)'); # Check exception handling of die my $did_not_die; eval { $hole2->call(sub{die "XXX\n"}); $did_not_die++ }; is($did_not_die, undef, 'Check exception handling of die - eval doesn\'t cause die'); is($@, "XXX\n", "\$\@ is populated"); ############################## # Backward compatible mode ############################### my $old_hole = new Safe::Hole; isa_ok($old_hole, 'Safe::Hole', 'New hole'); $::v = 'v in main'; is($old_hole->call( sub { eval '$v' }), 'v in main', "backwards compatible - old_hole"); # Alternate root my $old_hole2 = new Safe::Hole 'foo'; isa_ok($old_hole, 'Safe::Hole', 'New hole alternate root'); $foo::v = 1; # added to prevent warning: 'Name "foo::v" used only once: possible typo at t/01-hole.t line 107.' $foo::v = 'v in foo'; is($old_hole2->call( sub { eval '$v' }), 'v in foo', 'v in foo - alternate root'); # Check opcode mask not restored in backward compatible mode $op='eval "#Something forbidden"'; $old_hole->wrap(\&do_op,$safe,'&do_op_wrapped_old'); ok($safe->reval('do_op_wrapped_old()'), q{$safe->reval('do_op_wrapped_old()')}); ################################### # Test that require works ################################## $hole->wrap(sub { require File::Find; 1 },$safe,'&do_require'); ok(!($INC{'File/Find.pm'} || !$safe->reval('do_require') || !$INC{'File/Find.pm'}), 'Test that require works'); ################################## # Test that *INC not localised when it shouldn't be ################################## $old_hole->wrap(sub { no strict; my $inc='INC'; "@{[%$inc]}" },$safe,'&get_inc'); is($safe->reval('%INC = ( FOO => "./FOO.pm" ); &get_inc'), 'FOO ./FOO.pm', '%INC = ( FOO => "./FOO.pm" );'); ################################### # Test wrapping of objects ################################## # To do safe-hole-perl-0.13.orig/t/98-pod-coverage.t0000444000000000000000000000104711370360722015327 0ustar use strict; use warnings; use Test::More; # Ensure a recent version of Test::Pod::Coverage my $min_tpc = 1.08; eval "use Test::Pod::Coverage $min_tpc"; plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage" if $@; # Test::Pod::Coverage doesn't require a minimum Pod::Coverage version, # but older versions don't recognize some common documentation styles my $min_pc = 0.18; eval "use Pod::Coverage $min_pc"; plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" if $@; all_pod_coverage_ok(); safe-hole-perl-0.13.orig/t/99-pod.t0000444000000000000000000000035011370360722013533 0ustar #!perl -T use strict; use warnings; use Test::More; # Ensure a recent version of Test::Pod my $min_tp = 1.22; eval "use Test::Pod $min_tp"; plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; all_pod_files_ok();