Traverse the filepath given as argument by progressively removing the root of the path.

svn path=/trunk/boinc/; revision=13792
This commit is contained in:
Janus B. Kristensen 2007-10-08 07:51:30 +00:00
parent 9b66217202
commit 243e89d8ac
1 changed files with 15 additions and 1 deletions

View File

@ -29,8 +29,22 @@ function isSubDir($possibleSubDir, $parent){
$file = $_GET["file"];
if (!$file) throw new IllegalArgumentException("No file specified");
if (strpos(urldecode($file), "..")!==false) throw new IllegalArgumentException("Cannot use '..' in path");
// See if we've got the file
while (!$fileModTime){
if (($fileModTime = @filemtime($fileDirectory.$file)) === false){
$pos = strpos($file, "/", 1);
if ($pos === false){
throw new IllegalArgumentException("File does not exist");
} else {
$file = substr($file, $pos);
}
}
}
$file = $fileDirectory.$file;
if (($fileModTime = filemtime($file)) === false) throw new IllegalArgumentException("File does not exist");
if (!$fileFilter->isValid($file)) throw new IllegalArgumentException("File was not accepted by the server for tracking.");
// Everything's fine let's lookup the .torrent in the cache if needed: