Skip to content

Commit

Permalink
Ignore broken/dead symlinks on filescan
Browse files Browse the repository at this point in the history
This reverts commit 2c80a12
  • Loading branch information
IljaN committed Dec 15, 2017
1 parent 15eb6d9 commit d6905f5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ public function getSourcePath($path) {
if ($realPath) {
$realPath = $realPath . '/';
}

// Is broken symlink?
if (is_link($fullPath) && !file_exists($fullPath)) {
throw new ForbiddenException("$fullPath is a broken/dead symlink", false);
}

if (substr($realPath, 0, $this->dataDirLength) === $this->realDataDir) {
return $fullPath;
} else {
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/Files/Storage/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

namespace Test\Files\Storage;

use OC\Files\Storage\Local;

/**
* Class LocalTest
*
Expand All @@ -35,6 +37,9 @@ class LocalTest extends Storage {
*/
private $tmpDir;

/** @var Local */
protected $instance;

protected function setUp() {
parent::setUp();

Expand Down Expand Up @@ -107,5 +112,20 @@ public function testDisallowSymlinksInsideDatadir() {

$storage->file_put_contents('sym/foo', 'bar');
}

/**
* @expectedException \OCP\Files\ForbiddenException
*/
public function testBrokenSymlink() {

$linkTarget = $this->tmpDir . 'link_target';
$linkName = $this->tmpDir . 'broken_symlink';

mkdir($linkTarget);
symlink($linkTarget, $linkName);
rmdir($linkTarget);

$this->instance->getSourcePath('broken_symlink');
}
}

0 comments on commit d6905f5

Please sign in to comment.