2011-07-14 185 views
0

我正在使用一個Web服務器,用戶可以上傳一個zip文件。上傳後,應該解壓縮文件。我嘗試了系統命令unzip以及Archive::Extract模塊。我仍然得到錯誤:perl cgi解壓縮上傳的文件

Insecure dependency in eval while running with -T switch at /usr/lib/perl5/5.10.0/Module/Load/Conditional.pm line 332, <GEN3> line 34 

請幫助。

+2

而你的代碼是? – marto

+0

嘗試歸檔:: Zip –

回答

0

我猜你正在做的事情一樣

system "unzip $value_from_browser"; 

所以整個事情是shell代碼注入的邀請(文件名中的瀏覽器 「bla.zip; RM -fr *」)

使用multiargument語法,避免了殼:

system 'unzip', $value_from_browser; 
0

一個更安全的辦法可能是使用Archive::zip,這裏是我的一些工作的代碼,它應該給你如何做到這一點的要點。 Archive::zip模塊也有一些信息。

sub unpack_zipfiles 
{ 
my $zipfile = shift; # Name of uploaded zip file 
my $zip = Archive::Zip->new(); 
my $status = $zip->read($zipfile); 
if ($status == AZ_OK) 
    { 
    my @members = $zip->memberNames(); 
    my $n = 1; 
    foreach my $f (@members) 
     { 
     my @f2 = split(/\//,$f); 
# Part 1 - get a filename, and save the file 
     my $zf = getNextFile($f2[$#f2]); 
     my $unzipped = qq{$unpack_dir/$zf}; 
     $zip->extractMemberWithoutPaths($f,$unzipped); 
# Part 2 - check if it's new or the same, and adjust the filename if necessary 
     $zf = check_or_revert($unpack_dir,$zf,$f2[$#f2]); 
     $n++; 
     push @msgs,qq{Unzipped file: $zf}; 
# Add file to list of unpacked file (for diagnostic purposes) 
     push @{$data{unpacked}},$unzipped; 
# Unzipped files are plonked back in the file queue, because there is a loop that deals with them. 
     push @{$data{fileq}},$unzipped; 
     } 
    } 
else 
    { 
    die "Error: $zipfile is not a valid zip file, Zip status=$status"; 
    } 
}