diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-12-01 16:52:12 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-12-01 16:57:12 +0100 |
commit | b7f866988ee0c57045d58157130fbcb50e0d9e1b (patch) | |
tree | 7558308c40ffe1ba20019a4582d25c8bd9ba8a3a /lib/private/Files/View.php | |
parent | 5cea7f35e124ea7a6b8352a1d05c00069e8814ae (diff) | |
download | nextcloud-server-b7f866988ee0c57045d58157130fbcb50e0d9e1b.tar.gz nextcloud-server-b7f866988ee0c57045d58157130fbcb50e0d9e1b.zip |
Prevent endless loop in \OC\Files\View::createParentDirectories
\OC\Files\View::createParentDirectories was previously prone to an endless loop. If a path such as /foo/existingfile.txt/bar/foo was passed and existingfile.txt existed in foo the loop was never left and running until the PHP process timed out.
This commit changes the logic to a foreach loop over an array and additionally additional error handling using is_file.
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'lib/private/Files/View.php')
-rw-r--r-- | lib/private/Files/View.php | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 67f89180994..3ce21a3489b 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -2104,14 +2104,19 @@ class View { * @return bool */ private function createParentDirectories($filePath) { - $parentDirectory = dirname($filePath); - while(!$this->file_exists($parentDirectory)) { - $result = $this->createParentDirectories($parentDirectory); - if($result === false) { + $directoryParts = explode('/', $filePath); + $directoryParts = array_filter($directoryParts); + foreach($directoryParts as $key => $part) { + $currentPathElements = array_slice($directoryParts, 0, $key); + $currentPath = '/' . implode('/', $currentPathElements); + if($this->is_file($currentPath)) { return false; } + if(!$this->file_exists($currentPath)) { + $this->mkdir($currentPath); + } } - $this->mkdir($filePath); + return true; } } |