From aaebc34cbd58468262240b30229902aea0293c6c Mon Sep 17 00:00:00 2001 From: Patrik Fimml Date: Thu, 27 Jan 2011 11:06:15 +0100 Subject: [PATCH] Gracefully handle invalid repository paths * Check whether the path specified exists and refers to a directory. * Do not enter an endless loop when $repo/objects/pack/ does not exist. --- lib/git.class.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/git.class.php b/lib/git.class.php index c2d8d6d..8828fa8 100644 --- a/lib/git.class.php +++ b/lib/git.class.php @@ -89,13 +89,18 @@ static public function getTypeName($type) public function __construct($dir) { - $this->dir = $dir; + $this->dir = realpath($dir); + if ($this->dir === FALSE || !@is_dir($this->dir)) + throw new Exception(sprintf('not a directory: %s', $dir)); $this->packs = array(); $dh = opendir(sprintf('%s/objects/pack', $this->dir)); - while (($entry = readdir($dh)) !== FALSE) - if (preg_match('#^pack-([0-9a-fA-F]{40})\.idx$#', $entry, $m)) - $this->packs[] = sha1_bin($m[1]); + if ($dh !== FALSE) { + while (($entry = readdir($dh)) !== FALSE) + if (preg_match('#^pack-([0-9a-fA-F]{40})\.idx$#', $entry, $m)) + $this->packs[] = sha1_bin($m[1]); + closedir($dh); + } } /**