RonW has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Safe

Strangely, with the ":base_core" ops allowed, numeric constants cause a 'ref-to-glob cast' to be trapped. I am assuming I need to permit another op.

I have made the following test code to demonstrate the problem:

#!perl use strict; use warnings; use Safe; my $box = new Safe; $box->permit_only(':base_core'); my $vi = $box->reval('5',1); die "$@ " unless (defined $vi); print "vi=$vi\n";

Which die'd with the messaged 'ref-to-glob cast' trapped by operation mask at (eval 6) line 1.

Replies are listed 'Best First'.
Re: What additional ops needed for Safe::reval ?
by stevieb (Canon) on Feb 09, 2017 at 19:56 UTC

    I've never used Safe before, but I thought I'd take a crack.

    After I figured out which opcode is for the error (rv2gv, which is in :base_orig), I was getting:

    'private value' trapped by operation mask...

    So I found out which one took care of that (padany also in :base_orig):

    use strict; use warnings; use Safe; my $box = new Safe; $box->permit_only( ':base_core', 'rv2gv', # ref to glob cast 'padany' # private variable ); my $vi = $box->reval('5',1); die "$@ " unless (defined $vi); print "vi=$vi\n";

    Output:

    vi=5

    Note that the above can be simplified at the cost of allowing a bunch more opcodes implicitly:

    $box->permit_only(':base_core', ':base_orig');

    While doing some searching after figuring out the solution, I came across this: Perl opcode list.

Re: What additional ops needed for Safe::reval ? (why)
by Anonymous Monk on Feb 10, 2017 at 01:52 UTC