in reply to CGI file very odd
This looks strange to me:
$file =~ m/^.*(\\|\/)(.*)/; my $file_name = $2; open (FILE, "$name") or die "unable to open file";
Where is $name delcared? Oh, and the quotes around "$name" are unnecessary.
Also, what happens if somebody submits a filename like '>blah.txt'? Oops, you just deleted the contents of the file. As of perl 5.6, you can use a three-argument form of open() to avoid this problem:
open(FILE, '<', $name) or die "Can't open file: $!\n";Better still is to do some further cleansing on the name of the file. I see you at least have some basic matching, but even better is to restrict exactly what files are allowed to be submitted via a hash:
my %allowed_files = ( file1 => '/path/to/file1', file2 => '/path/to/file2', file3 => '/path/to/file3', ); # $file already processed from CGI params my $file_name = defined($allowed_files{$file}) ? $allowed_files{$file} : die "Bad file name\n";
Admittedly, the above might become a maintence nightmare, depending on the number of files on your allowed list and if that list changes a lot.
|
|---|