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
In reply to Auditing BEGIN blocks? by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |