Skip to content

Commit

Permalink
Gracefully handle invalid repository paths
Browse files Browse the repository at this point in the history
* Check whether the path specified exists and refers to a directory.
* Do not enter an endless loop when $repo/objects/pack/ does not exist.
  • Loading branch information
patrikf committed Jan 27, 2011
1 parent 1aa77ed commit aaebc34
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/git.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down

0 comments on commit aaebc34

Please sign in to comment.