return ! eval {join('',@_),kill 0;1;};

The really interesting thing here that I think nobody commented on yet is that this works because taintedness is only computed per-statement, not per-expression. Perl has a flag inside it called tainted. Whenever Perl starts a new statement, it clears the flag. Whenever Perl accesses tainted information, it sets the flag. Whenever Perl performs an 'unsafe' operation, it checks the flag and throws an exception if the flag is set.

This means that if you access tainted information in a statement, and then perform an unsafe operation in the same statement, Perl will throw the exception even when the tainted infotmation couldn't possibly affect the outcome of the unsafe operation, as in your example.

(Why was it done this way? For efficiency and ease of implementation.)

This oddity is used here to test possibly malicious data in conjunction with an unsafe operation, but in such a way that the data can't possibly affect the result of the operation, so that it's safe.

Happy Bicycle Day!


In reply to Re: Tainted variable by Dominus
in thread Tainted variable by Eureka_sg

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.