summaryrefslogtreecommitdiffstats
path: root/lib/files
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-12 15:44:20 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-12 15:44:20 -0700
commitd5ddbfb04562ba69a94d05413b931a4b378f0220 (patch)
tree7c73eb0ce8e4f61be5a8361a0c93abb16fadea9c /lib/files
parentc7ca86799b2608609ead7ecd2d84d0bbd47c6548 (diff)
parentc01675de5d6650c7b1cd0571d8c313f21d13c33c (diff)
downloadnextcloud-server-d5ddbfb04562ba69a94d05413b931a4b378f0220.tar.gz
nextcloud-server-d5ddbfb04562ba69a94d05413b931a4b378f0220.zip
Merge pull request #4719 from owncloud/port_4701_master
Always check variable type before using readdir to avoid surprises
Diffstat (limited to 'lib/files')
-rw-r--r--lib/files/cache/scanner.php28
-rw-r--r--lib/files/storage/common.php21
-rw-r--r--lib/files/storage/mappedlocal.php18
-rw-r--r--lib/files/view.php8
4 files changed, 42 insertions, 33 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 87fa7c1365a..9d180820e9d 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -159,20 +159,22 @@ class Scanner extends BasicEmitter {
$newChildren = array();
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
\OC_DB::beginTransaction();
- while (($file = readdir($dh)) !== false) {
- $child = ($path) ? $path . '/' . $file : $file;
- if (!Filesystem::isIgnoredDir($file)) {
- $newChildren[] = $file;
- $data = $this->scanFile($child, $reuse, true);
- if ($data) {
- if ($data['size'] === -1) {
- if ($recursive === self::SCAN_RECURSIVE) {
- $childQueue[] = $child;
- } else {
- $size = -1;
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ $child = ($path) ? $path . '/' . $file : $file;
+ if (!Filesystem::isIgnoredDir($file)) {
+ $newChildren[] = $file;
+ $data = $this->scanFile($child, $reuse, true);
+ if ($data) {
+ if ($data['size'] === -1) {
+ if ($recursive === self::SCAN_RECURSIVE) {
+ $childQueue[] = $child;
+ } else {
+ $size = -1;
+ }
+ } else if ($size !== -1) {
+ $size += $data['size'];
}
- } else if ($size !== -1) {
- $size += $data['size'];
}
}
}
diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php
index 01560f34fde..a5b79f0e967 100644
--- a/lib/files/storage/common.php
+++ b/lib/files/storage/common.php
@@ -142,13 +142,15 @@ abstract class Common implements \OC\Files\Storage\Storage {
return false;
} else {
$directoryHandle = $this->opendir($directory);
- while (($contents = readdir($directoryHandle)) !== false) {
- if (!\OC\Files\Filesystem::isIgnoredDir($contents)) {
- $path = $directory . '/' . $contents;
- if ($this->is_dir($path)) {
- $this->deleteAll($path);
- } else {
- $this->unlink($path);
+ if(is_resource($directoryHandle)) {
+ while (($contents = readdir($directoryHandle)) !== false) {
+ if (!\OC\Files\Filesystem::isIgnoredDir($contents)) {
+ $path = $directory . '/' . $contents;
+ if ($this->is_dir($path)) {
+ $this->deleteAll($path);
+ } else {
+ $this->unlink($path);
+ }
}
}
}
@@ -224,7 +226,8 @@ abstract class Common implements \OC\Files\Storage\Storage {
}
private function addLocalFolder($path, $target) {
- if ($dh = $this->opendir($path)) {
+ $dh = $this->opendir($path);
+ if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file !== '.' and $file !== '..') {
if ($this->is_dir($path . '/' . $file)) {
@@ -242,7 +245,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
protected function searchInDir($query, $dir = '') {
$files = array();
$dh = $this->opendir($dir);
- if ($dh) {
+ if (is_resource($dh)) {
while (($item = readdir($dh)) !== false) {
if ($item == '.' || $item == '..') continue;
if (strstr(strtolower($item), strtolower($query)) !== false) {
diff --git a/lib/files/storage/mappedlocal.php b/lib/files/storage/mappedlocal.php
index fbf1b4ebf96..ba5ac4191c5 100644
--- a/lib/files/storage/mappedlocal.php
+++ b/lib/files/storage/mappedlocal.php
@@ -65,16 +65,18 @@ class MappedLocal extends \OC\Files\Storage\Common{
$logicalPath = $this->mapper->physicalToLogic($physicalPath);
$dh = opendir($physicalPath);
- while (($file = readdir($dh)) !== false) {
- if ($file === '.' or $file === '..') {
- continue;
- }
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if ($file === '.' or $file === '..') {
+ continue;
+ }
- $logicalFilePath = $this->mapper->physicalToLogic($physicalPath.'/'.$file);
+ $logicalFilePath = $this->mapper->physicalToLogic($physicalPath.'/'.$file);
- $file= $this->mapper->stripRootFolder($logicalFilePath, $logicalPath);
- $file = $this->stripLeading($file);
- $files[]= $file;
+ $file= $this->mapper->stripRootFolder($logicalFilePath, $logicalPath);
+ $file = $this->stripLeading($file);
+ $files[]= $file;
+ }
}
\OC\Files\Stream\Dir::register('local-win32'.$path, $files);
diff --git a/lib/files/view.php b/lib/files/view.php
index 98a04486690..6d58bcd9918 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -500,9 +500,11 @@ class View {
} else {
if ($this->is_dir($path1) && ($dh = $this->opendir($path1))) {
$result = $this->mkdir($path2);
- while (($file = readdir($dh)) !== false) {
- if (!Filesystem::isIgnoredDir($file)) {
- $result = $this->copy($path1 . '/' . $file, $path2 . '/' . $file);
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if (!Filesystem::isIgnoredDir($file)) {
+ $result = $this->copy($path1 . '/' . $file, $path2 . '/' . $file);
+ }
}
}
} else {