in reply to Re^2: Tainting problem on Strawberry perl
in thread Tainting problem on Strawberry perl

Which component could have broken this? File::Spec maybe?

Looks likely. Using the test case that ikegami provided, I find that I get his (correct) output with File::Spec::Win32-3.2501. But when I update to PathTools-3.2701, I get your (broken) output.

Cheers,
Rob
  • Comment on Re^3: Tainting problem on Strawberry perl

Replies are listed 'Best First'.
Re^4: Tainting problem on Strawberry perl
by ikegami (Patriarch) on Feb 28, 2008 at 23:52 UTC

    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.