Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insecure dependency in open while running with -T switch [PERL]

Tags:

fork

perl

taint

I have a function like this:

open my $pipe, "-|", '/usr/bin/externalcmd | /usr/bin/awk \'{print $2" "$4}\''
    || die "can't fork command: $!";    

while (<$pipe>) { 
    my ($if, $ip) = split;

    my $file = "/some/file/$if";
    open (FILE, ">$file") || die "can't open $file for $ip: $!";
    
    # ...

    close(FILE);
}    
close ($pipe);

It fails on open with the following error:

Insecure dependency in open while running with -T switch at line 1383, <$pipe> line 1.

How can I fix this?

like image 314
Lucky Avatar asked Dec 20 '25 17:12

Lucky


1 Answers

The answer was to "launder" the $if variable through a regex match like this:

# e.g., only "word" characters
if ($if =~ /^([-\@\w.]+)\z/) {
    $if = $1;
} else {
    die "Bad data in '$if'";
}

Then proceed as before.

like image 57
Lucky Avatar answered Dec 23 '25 07:12

Lucky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!