]> source.dussan.org Git - nextcloud-server.git/commitdiff
prevent infinite recursion while getting storage from mount 1007/head
authorRobin Appelman <robin@icewind.nl>
Mon, 22 Aug 2016 13:12:39 +0000 (15:12 +0200)
committerRobin Appelman <robin@icewind.nl>
Tue, 23 Aug 2016 12:52:18 +0000 (14:52 +0200)
apps/files_sharing/lib/sharedstorage.php
lib/private/Files/Mount/MountPoint.php
tests/lib/Files/Mount/MountPointTest.php

index b67c9c5efb47f969a63dc26ff2c8ea2110ffb669..6dec020982e7492db2ea25c26c6dcea30e356867 100644 (file)
@@ -401,6 +401,10 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage {
                // shares do not participate in availability logic
        }
 
+       public function getSourceStorage() {
+               return $this->getWrapperStorage();
+       }
+
        public function getWrapperStorage() {
                $this->init();
                return $this->storage;
index 8b8f0574ae0ae4299d81cae3a4acf24e7cf5e337..4aef340149c797baaf9c122cc87f9754f615abb4 100644 (file)
@@ -70,7 +70,7 @@ class MountPoint implements IMountPoint {
         */
        private $invalidStorage = false;
 
-       /** @var int|null  */
+       /** @var int|null */
        protected $mountId;
 
        /**
@@ -132,18 +132,20 @@ class MountPoint implements IMountPoint {
 
        /**
         * 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!
@@ -151,12 +153,12 @@ class MountPoint implements IMountPoint {
                                } 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;
                }
        }
 
@@ -165,7 +167,7 @@ class MountPoint implements IMountPoint {
         */
        public function getStorage() {
                if (is_null($this->storage)) {
-                       $this->storage = $this->createStorage();
+                       $this->createStorage();
                }
                return $this->storage;
        }
index 392f10c71704c1e4f1b222ee5cd765531b81e61e..799f441a1aba661be84c4cc650f6cb362315a9d3 100644 (file)
@@ -16,9 +16,9 @@ class MountPointTest extends \Test\TestCase {
                        ->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(
@@ -38,9 +38,9 @@ class MountPointTest extends \Test\TestCase {
        }
 
        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;