karlgoethebier has asked for the wisdom of the Perl Monks concerning the following question:
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...
Thank you very much for any hint and best regards,
Karl
«The Crux of the Biscuit is the Apostrophe»
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Safe.pm: Which parameter for permit_only? (Safest Undumper of Data::Dumper)
by Anonymous Monk on Jun 13, 2014 at 13:18 UTC | |
|
Re: Safe.pm: Which parameter for permit_only?
by Anonymous Monk on Jun 13, 2014 at 11:35 UTC | |
|
Re: Safe.pm: Which parameter for permit_only?
by Anonymous Monk on Jun 13, 2014 at 12:38 UTC | |
by Anonymous Monk on Jun 13, 2014 at 12:57 UTC | |
by karlgoethebier (Abbot) on Jun 14, 2014 at 10:03 UTC | |
by Anonymous Monk on Jun 14, 2014 at 10:42 UTC | |
|
Re: Safe.pm: Which parameter for permit_only?
by lost953 (Acolyte) on Sep 24, 2019 at 22:05 UTC | |
by karlgoethebier (Abbot) on Sep 28, 2019 at 12:50 UTC |