Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
sensible way to untaint $ENV{'PATH'} without losing the portability

Just set $ENV{'PATH'} to /bin:/usr/bin. That's what you get by default when nothing else is set (default set in init, libc, and some other places), and that's where all important binaries can be found. If you need "exotic programs" that are not in /bin or /usr/bin, put their path into the configuration file.

my $path = $ENV{'PATH'}; $ENV{'PATH'} = undef; foreach my $p(split /:/, $path) { if ($p =~ m!^(/(usr|bin).*)!) { $ENV{'PATH'} .= ':' if $ENV{'PATH'}; $ENV{'PATH'} .= $1; } }

That looks broken.

You add every element of PATH to the new PATH if it starts with /usr or /bin. Including /usr/u0/ (that's how HOME once looked like, before /home became common), /binary/garbage, /usr.corrupted, /usr/sbin, /usr/svr4/bin, /usr/etc, and so on.

Also, why don't you use join to combine the "cleaned" elements?

Just don't. The predefined PATH is unreliable, that's why perl considers it tainted. Set a sane default, don't try to repair the mess found in PATH. It just makes things worse. /bin:/usr/bin is sane.


Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^3: Insecure CPAN module in taint mode by afoken
in thread Insecure CPAN module in taint mode by Bod

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-06-25 04:45 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (81 votes). Check out past polls.