Playing around with Safe.pm to write a prog that would safely allow users
to enter test strings and regexes and test matching.
Found the following:
#!/usr/bin/perl -w
use Safe;
$c = new Safe;
$c->permit_only(
qw(
leaveeval
const
));
$result = $c->reval('"A" =~ m/a/i') ? 'YES' : 'NO';
die "$@\n" if $@;
print "\$result = $result\n";
__END__
This works, even though I didn't permit 'match'.
Current output is "$result = YES".
Changing regex to delete the i causes "$result = NO"
eliminating either OP in the permit_only() cause the $c->reval to fail
compilation with "<OP> item trapped by operation mask at (eval 2) line
1", as expected.
Shouldn't I need to permit 'match' for this to pass reval()?
This happens on perl 5.005_03, 5.6.0 and 5.8.0 on Linux, and , perl 5.6.1 form Activestate on WinNT. (The code on 5.8.0 permitted a few more OPs but still worked without 'match'). Since it happens on so many systems, I'm thinking I'm just missing something obvious.
--Bob Niederman, http://bob-n.com
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.