in reply to Passing argument into STDIN inside safe.pm reval
Actually, Safe has a share() method, which you should be able to use on STDIN--but it doesn't work for me:
use strict; use warnings; use 5.012; use Safe; if($ARGV[0]) { my $code = $ARGV[0]; my $compartment = Safe->new; $compartment->share('*STDIN'); $compartment->permit_only(qw{ print readline }); $compartment->reval($code); if ($@) { print "Unsafe code detected: $@"; } } --output:-- $ perl 2.pl ' print "Enter some stdin: "; my $line = readline *STDIN; print "From STDIN: $line"; ' Unsafe code detected: 'private value' trapped by operation mask at (ev +al 5) line 1.
I can't even get share() to work on a simple scalar variable:
use strict; use warnings; use 5.012; use Safe; our $x = 10; if($ARGV[0]) { my $code = $ARGV[0]; my $compartment = Safe->new; $compartment->share('$x'); $compartment->permit_only(qw{ print readline}); $compartment->reval($code); if ($@) { print "Unsafe code detected: $@"; } } --output:-- $ perl 2.pl 'print "$x\n";' Unsafe code detected: 'private value' trapped by operation mask at (ev +al 5) line 1.
I'm really sick of that non-informative error message!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing argument into STDIN inside safe.pm reval
by gideondsouza (Pilgrim) on Feb 12, 2013 at 05:20 UTC | |
|
Re^2: Passing argument into STDIN inside safe.pm reval
by Dallaylaen (Chaplain) on Feb 12, 2013 at 10:53 UTC | |
by 7stud (Deacon) on Feb 12, 2013 at 18:06 UTC | |
by Dallaylaen (Chaplain) on Feb 14, 2013 at 21:14 UTC |