dtreder has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to use Safe to protect against eval of strings, but allow the use of eval for catching exceptions (in other words, allow "entertry" and forbid "entereval").
By default, Safe protects you from "entereval" (eval of a string). However this script breaks on eval {} - which is for catching exceptions.
Why does Safe think the use of eval {} is actually eval of string? Is there a way I can use safe while permitting catching of exceptions?
Basically I want reval(' eval "code"; ') to fail and I want reval(' eval { 1 }; ') to succeed.use strict; use Safe; my $SafeCompartment = new Safe; $SafeCompartment->permit(qw(entertry)); my $evalbrace =' eval { 1 } ; '; $SafeCompartment->reval($evalbrace, 1); if ($@) { die "WARNING!: evalbrace failed: $@"; } ./testsafeexecute WARNING!: evalbrace failed: eval "string" trapped by operation mask at + (eval 2) line 2.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Safe.pm is broken - entertry fails
by waswas-fng (Curate) on Dec 18, 2003 at 20:08 UTC | |
by dtreder (Novice) on Dec 18, 2003 at 20:32 UTC |