From 243e89d8ac58f27eef3ffbceba80be72772021e9 Mon Sep 17 00:00:00 2001 From: "Janus B. Kristensen" Date: Mon, 8 Oct 2007 07:51:30 +0000 Subject: [PATCH] Traverse the filepath given as argument by progressively removing the root of the path. svn path=/trunk/boinc/; revision=13792 --- html/bt/torrent_cache.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/html/bt/torrent_cache.php b/html/bt/torrent_cache.php index 7201d90171..cf980de119 100755 --- a/html/bt/torrent_cache.php +++ b/html/bt/torrent_cache.php @@ -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: