The key is that it uses $_[0] as part of the argument to the kill function. That function is affected by taint checks; if $_[0] is tainted, Perl will refuse to let it or something calculated from get passed to kill. It will raise an exception instead.

Normally, an exception aborts your program. However, in this case, the statement in question is inside an eval BLOCK construct. If an exception occurs inside, only the code in that block is aborted, and the surrounding code can examine the exception by looking at the $@ variable. The above code does that to check whether it's a Perl error message starting with "Insecure", which would happen if $_[0] was tainted.

Multiplying $_[0] with zero is a trick. If $_[0] is not tainted, kill will be called. Despite the name, kill does not necessarily kill processes; it sends them signals. By multiplying with zero, you make sure that you always send signal zero, and that is a no-op that does nothing to the receiving process. Sending signal zero is normally used to check if a process with the given PID exists.

Makeshifts last the longest.


In reply to Re: Please explain this tainting behaviour by Aristotle
in thread Please explain this tainting behaviour by Anonymous Monk

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.