I just thought of this, so correct me if I'm doing something naive.

If you have to get the values of $program1 and $program2 from an outside source, you can put allowed values in a hash like this:

my %allowed; $allowed{'ls'} = '/bin/ls'; $allowed{'grep'} = '/bin/grep'; $allowed{'gzip'} = '/bin/gzip'; . . .

When it comes time to execute the program:

my $good_prog = $allowed{$program1}; system($good_prog) if($good_prog != undef);

This won't help you with arguments, of course. Also, you'll be limiting the actual programs that can be run (which is probably a good thing). If you want to allow everything in /bin and /usr/bin, try this (untested):

use File::Find; my %allowed; find(\&add, '/bin', '/usr/bin'); sub add { $allowed{$_} = $File::Find::name; }

In reply to Re: Re: system, pipes, shell, quoting by hardburn
in thread system, pipes, shell, quoting by superpete

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.