Bingo! It is as I suspected in my initial post. I was confused in my latter posts because I was looking at the wrong version.

Changes to $1 results in changes to $_[1], since $_[1] is aliased to $1. I was looking at the version in perl-5.10.0, not the one from PathTools-3.2701. The one in perl-5.10.0 copies @_ into local variables, so it works fine. The one in Pathtools-3.2701 works with @_ directly, so it picks up the change to $1.

That technically makes the bug PathTools's, since it should localize the globlals it modifies (like $1). However, it's rarely done (especially for $1, $! and $@) and it's actually rather hard to do when working with @_ directly and package variables (like $1), so it's best not to pass globals to functions and to follow the tips I already posted.

Update: Here's some code the illustrate the issue.

sub f_bad { 'b' =~ /(.*)/; return $_[0]; } sub f_good1 { my ($var) = @_; 'b' =~ /(.*)/; return $var; } sub f_good2 { { local $1; 'b' =~ /(.*)/; } return $_[0]; } 'a' =~ /(.*)/; print f_bad($1), "\n"; # b 'a' =~ /(.*)/; print f_good1($1), "\n"; # a 'a' =~ /(.*)/; print f_good2($1), "\n"; # a

Unforunately, sub { local $1; 'b' =~ /(.*)/; return $_[0]; } doesn't work since local doesn't create a new variable.


In reply to Re^4: Tainting problem on Strawberry perl by ikegami
in thread Tainting problem on Strawberry perl by EvanCarroll

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.