diotalevi has asked for the wisdom of the Perl Monks concerning the following question:
I'm sort of stewing some ideas how to locally lock down sections of a program so that a restricted section isn't able to see or modify things it hasn't already been given access to. An idea is to start using B::Util to look for specifically disallowed constructions like unpack "p", pack 'p', "foo". One of the immediate problems is how do the same auditing for BEGIN blocks in the about-to-be-called code. AFAIK there's no way to run this sort of code on a BEGIN block to audit it. Ideas?
This spot of code (blatantly unfinished with all sorts of holes) checks pack's first argument for 'P' or 'p' if the argument is a constant. This could be beefed up but not just now.
BEGIN { use B::Utils qw(opgrep walkallops_filtered); walkallops_filtered ( # Search for pack() with a constant first arg sub { opgrep( { name => 'pack', first => { name => 'const' } } ) }, sub { my $pack = shift; my $const = $pack->first; # Disallow p and P if ($const->pv =~ m/p/i) { die "Format p or P was used in pack" } } ); }
Fun Fun Fun in the Fluffy Chair
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Auditing BEGIN blocks?
by PodMaster (Abbot) on Dec 18, 2002 at 16:24 UTC | |
by merlyn (Sage) on Dec 18, 2002 at 20:18 UTC | |
by diotalevi (Canon) on Dec 18, 2002 at 16:55 UTC | |
|
Re: Auditing BEGIN blocks?
by John M. Dlugosz (Monsignor) on Dec 18, 2002 at 17:06 UTC | |
by diotalevi (Canon) on Dec 19, 2002 at 04:49 UTC | |
by John M. Dlugosz (Monsignor) on Dec 19, 2002 at 19:16 UTC | |
by diotalevi (Canon) on Dec 20, 2002 at 17:16 UTC |