fireartist has asked for the wisdom of the Perl Monks concerning the following question:
I have tried running a regex on $ENV{PATH}, and it wasn't that, so I'm not sure what is failing Taint.open (FILEOUT, "> $file_out") or die "Couldn't create output file:\n$!\n";
#!/usr/bin/perl -wT use strict; use MIME::Base64; my $file_in = 'base64data'; ### get variables chomp (my $file_out = <STDIN>); my $data_enc; my $data_unenc; $ENV{PATH} = ""; ### check file_in unless ($file_in =~ /^[\w][\w\._-]*$/) { print "Insecure file_in\n"; exit; } if ($file_in =~ /^\.{2,}$/) { print "Insecure file_in path\n"; exit; } ### untaint file_out unless ($file_out =~ /[\w][\w\._-]*$/) { print "Insecure file_out\n"; exit; } if ($file_out =~ /^\.{2,}$/) { print "Insecure file_out path\n"; exit; } ### get the data from input_file open (FILEIN, "< $file_in") or die "Couldn't open input file:\n$!\n"; while (<FILEIN>) { $data_enc .= $_; } close (FILEIN); ### unencode the data $data_unenc = decode_base64($data_enc); ### write the data to the output file open (FILEOUT, "> $file_out") or die "Couldn't create output file:\n$!\n"; print FILEOUT $data_unenc; close (FILEOUT); ### finish print "Operation successful.\n"; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Taint problem opening file to write
by derby (Abbot) on Apr 30, 2002 at 12:35 UTC | |
by fireartist (Chaplain) on Apr 30, 2002 at 12:54 UTC | |
|
Re: Taint problem opening file to write
by Necos (Friar) on Apr 30, 2002 at 12:41 UTC | |
by jeffa (Bishop) on Apr 30, 2002 at 14:26 UTC | |
by derby (Abbot) on Apr 30, 2002 at 14:37 UTC |