Hi all,

i use the cc tool that comes with Astaro firewalls to get some information about the status of several tunnels (cc get_ipsec_status).

The output is pure Perl, like this:
{ 'foo' => 'bar', 'nose' => 'cuke', }

For some paranoid reasons, i considered using Safe to read this output:

use Safe; use strict; use warnings; use Data::Dumper; undef $/; my $string = <DATA>; my $compartment = Safe->new(); # $compartment->permit_only(qw(???)); # <-- my $hash_ref = $compartment->reval($string); die $@ if $@; print Dumper($hash_ref); __DATA__ # qx(); { 'foo' => 'bar', 'nose' => 'cuke', } __END__ 'quoted execution (``, qx)' trapped by operation mask at (eval 6) line + 1, <DATA> chunk 1. $VAR1 = { 'foo' => 'bar', 'nose' => 'cuke' };

This works - if i uncomment qx() this gets trapped as one can see in the output of my script.

Safe uses per default the :default tag from Opcode which is a shorthand for :base_core :base_mem :base_loop :base_orig :base_thread.

Too much. What parameter must i pass to permit_only only for reading this data structure? I couldn't figure out this by reading the Opcode manpage :-(

Update:

First, thanks to all for answering. I wasn't in office this week due to a little illness so my answer is a bit late, sorry.

But my proxy fiddled out this by Trial-And-Error:

$compartment->permit_only(qw(lineseq padany const leaveeval pushmark l +ist anonhash));

Strange enough. It seems like this works nice with v5.16.3 but please see what happens:

karls-mac-mini:monks karl$ perl -v This is perl 5, version 16, subversion 3 (v5.16.3) built for darwin-2l +evel karls-mac-mini:monks karl$ ./testomato.pl { 'foo' => 'bar', 'nose' => 'cuke', }; { foo => "bar", nose => "cuke" } karls-mac-mini:monks karl$ perlbrew use perl-5.17.7 karls-mac-mini:monks karl$ ./testomato.pl { 'foo' => 'bar', 'nose' => 'cuke', }; { foo => "bar", nose => "cuke" } karls-mac-mini:monks karl$ perlbrew use perl-5.18.0 karls-mac-mini:monks karl$ ./testomato.pl { 'foo' => 'bar', 'nose' => 'cuke', }; 'ref-to-glob cast' trapped by operation mask at (eval 5) line 1, <DATA +> chunk 1. undef karls-mac-mini:monks karl$ perlbrew use perl-5.18.1 karls-mac-mini:monks karl$ ./testomato.pl { 'foo' => 'bar', 'nose' => 'cuke', }; 'ref-to-glob cast' trapped by operation mask at (eval 5) line 1, <DATA +> chunk 1. undef

Very bad... seems like it depends on the version of Perl...

See also

Thank you very much for any hint and best regards,

Karl

«The Crux of the Biscuit is the Apostrophe»


In reply to Safe.pm: Which parameter for permit_only? by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.