Skip to content

Commit

Permalink
prevent infinite recursion while getting storage from mount
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Aug 23, 2016
1 parent 1e7c108 commit a0c2342
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 4 additions & 0 deletions apps/files_sharing/lib/sharedstorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ public function setAvailability($available) {
// shares do not participate in availability logic
}

public function getSourceStorage() {
return $this->getWrapperStorage();
}

public function getWrapperStorage() {
$this->init();
return $this->storage;
Expand Down
18 changes: 10 additions & 8 deletions lib/private/Files/Mount/MountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class MountPoint implements IMountPoint {
*/
private $invalidStorage = false;

/** @var int|null */
/** @var int|null */
protected $mountId;

/**
Expand Down Expand Up @@ -132,31 +132,33 @@ public function setMountPoint($mountPoint) {

/**
* create the storage that is mounted
*
* @return \OC\Files\Storage\Storage
*/
private function createStorage() {
if ($this->invalidStorage) {
return null;
return;
}

if (class_exists($this->class)) {
try {
return $this->loader->getInstance($this, $this->class, $this->arguments);
$class = $this->class;
// prevent recursion by setting the storage before applying wrappers
$this->storage = new $class($this->arguments);
$this->storage = $this->loader->wrap($this, $this->storage);
} catch (\Exception $exception) {
$this->storage = null;
$this->invalidStorage = true;
if ($this->mountPoint === '/') {
// the root storage could not be initialized, show the user!
throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
} else {
\OCP\Util::writeLog('core', $exception->getMessage(), \OCP\Util::ERROR);
}
return null;
return;
}
} else {
\OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', \OCP\Util::ERROR);
$this->invalidStorage = true;
return null;
return;
}
}

Expand All @@ -165,7 +167,7 @@ private function createStorage() {
*/
public function getStorage() {
if (is_null($this->storage)) {
$this->storage = $this->createStorage();
$this->createStorage();
}
return $this->storage;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/Files/Mount/MountPointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public function testGetStorage() {
->method('getId')
->will($this->returnValue(123));

$loader = $this->getMock('\OCP\Files\Storage\IStorageFactory');
$loader = $this->getMock('\OC\Files\Storage\StorageFactory');
$loader->expects($this->once())
->method('getInstance')
->method('wrap')
->will($this->returnValue($storage));

$mountPoint = new \OC\Files\Mount\MountPoint(
Expand All @@ -38,9 +38,9 @@ public function testGetStorage() {
}

public function testInvalidStorage() {
$loader = $this->getMock('\OCP\Files\Storage\IStorageFactory');
$loader = $this->getMock('\OC\Files\Storage\StorageFactory');
$loader->expects($this->once())
->method('getInstance')
->method('wrap')
->will($this->throwException(new \Exception('Test storage init exception')));

$called = false;
Expand Down

0 comments on commit a0c2342

Please sign in to comment.