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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.