lstein has asked for the wisdom of the Perl Monks concerning the following question:
I want to compile an anonymous subroutine within a Safe compartment, and then execute it from outside. This does not seem to work correctly. If I create a compartment that forbids file operations, and compile an anonymous subroutine that uses IO::File to open a file, it executes properly without complaint:
If I replace IO::File->new with a direct call to open(), then the call is trapped, as desired. Is there a way to prevent anonymous subs defined within Safe compartments from invoking Class methods?my $code =<<'END'; sub { my $a = ''; my $f = IO::File->new('/etc/passwd'); while (my $l = $f->getline) { $a .= $l } return $a; } END my $compartment = Safe->new(':default'); $safe = $compartment->reval($code); print $safe->();
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to use Safe to compile anonymous subs
by moritz (Cardinal) on Jul 30, 2008 at 19:01 UTC | |
by lstein (Novice) on Jul 30, 2008 at 19:27 UTC | |
by moritz (Cardinal) on Jul 30, 2008 at 19:50 UTC | |
by Perlbotics (Archbishop) on Jul 30, 2008 at 20:04 UTC | |
by rir (Vicar) on Jul 30, 2008 at 20:02 UTC | |
Re: How to use Safe to compile anonymous subs
by zshzn (Hermit) on Jul 30, 2008 at 23:00 UTC |
Back to
Seekers of Perl Wisdom