Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: FindBin and Tainted

by haj (Curate)
on Aug 14, 2020 at 10:36 UTC ( #11120719=note: print w/replies, xml ) Need Help??

in reply to FindBin and Tainted

You can apply the usual untainting mantra by also using a BEGIN section:

use strict; use warnings; use FindBin 1.51 qw( $RealBin ); BEGIN { ($RealBin) = $RealBin =~ /(.+)/; } use lib "$RealBin/../lib"; use MyLib;

Of course, you need to trust your installation to not mess with the current working directory (because this is why $RealBin comes out tainted in the first place).

Replies are listed 'Best First'.
Re^2: FindBin and Tainted
by mikkoi (Sexton) on Aug 14, 2020 at 23:57 UTC
    This works. But is there any way to do the same without using the same $RealBin variable (which belongs to FindBin)?

      Sure, you can use a copy, to be declared outside of the BEGIN block:

      use strict; use warnings; use FindBin 1.51 qw( $RealBin ); my $untainted_bin; BEGIN { ($untainted_bin) = $RealBin =~ /(.+)/; } use lib "$untainted_bin/../lib"; use MyLib;
        Thanks. This is beautiful. I improved it a little. Probably more portable with File::Spec.
        use FindBin 1.51 qw( $RealBin ); use File::Spec; my $lib_path; BEGIN { $lib_path = File::Spec->catdir(($RealBin =~ /(.+)/msx)[0], q{..}, +'lib'); } use lib "$lib_path";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11120719]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2021-01-27 16:38 GMT
Find Nodes?
    Voting Booth?