aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/SimpleFS
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-02-09 20:15:29 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-02-27 13:35:09 +0100
commit8b5997483c852bcee6b44188982073c8213de25f (patch)
treedfa93059b717471deed9840c3ac86586055badab /lib/private/Files/SimpleFS
parentd0a6368a8bc9b03cba66c4a485aa001da187b2e3 (diff)
downloadnextcloud-server-8b5997483c852bcee6b44188982073c8213de25f.tar.gz
nextcloud-server-8b5997483c852bcee6b44188982073c8213de25f.zip
Hardening of SimpleFile getContent
if file_get_contents fails remove the file. And traverse up the tree checking if the other folders are there. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Files/SimpleFS')
-rw-r--r--lib/private/Files/SimpleFS/SimpleFile.php36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/private/Files/SimpleFS/SimpleFile.php b/lib/private/Files/SimpleFS/SimpleFile.php
index 5eadfd98b60..1f2b497a192 100644
--- a/lib/private/Files/SimpleFS/SimpleFile.php
+++ b/lib/private/Files/SimpleFS/SimpleFile.php
@@ -23,6 +23,7 @@
namespace OC\Files\SimpleFS;
use OCP\Files\File;
+use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
@@ -79,10 +80,18 @@ class SimpleFile implements ISimpleFile {
/**
* Get the content
*
+ * @throws NotPermittedException
+ * @throws NotFoundException
* @return string
*/
public function getContent() {
- return $this->file->getContent();
+ $result = $this->file->getContent();
+
+ if ($result === false) {
+ $this->checkFile();
+ }
+
+ return $result;
}
/**
@@ -96,6 +105,31 @@ class SimpleFile implements ISimpleFile {
}
/**
+ * Sometimes there are some issues with the AppData. Most of them are from
+ * user error. But we should handle them gracefull anyway.
+ *
+ * If for some reason the current file can't be found. We remove it.
+ * Then traverse up and check all folders if they exists. This so that the
+ * next request will have a valid appdata structure again.
+ *
+ * @throws NotFoundException
+ */
+ private function checkFile() {
+ $cur = $this->file;
+
+ while ($cur->stat() === false) {
+ $parent = $cur->getParent();
+ $cur->delete();
+ $cur = $parent;
+ }
+
+ if ($cur !== $this->file) {
+ throw new NotFoundException('File does not exist');
+ }
+ }
+
+
+ /**
* Delete the file
*
* @throws NotPermittedException