summaryrefslogtreecommitdiffstats
path: root/lib/cache
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2013-09-04 13:06:04 +0200
committerArthur Schiwon <blizzz@owncloud.com>2013-09-04 13:06:04 +0200
commitec3639dc7a28348b136d2008e692cffe8c3753ad (patch)
tree3d197d325496925be0ddee1f1ab22c48c7c817a1 /lib/cache
parent09187f3b3b30e6f810c6afff7332615ed472154e (diff)
downloadnextcloud-server-ec3639dc7a28348b136d2008e692cffe8c3753ad.tar.gz
nextcloud-server-ec3639dc7a28348b136d2008e692cffe8c3753ad.zip
Always check variable type before using readdir to avoid surprises
Diffstat (limited to 'lib/cache')
-rw-r--r--lib/cache/file.php11
-rw-r--r--lib/cache/fileglobal.php20
2 files changed, 20 insertions, 11 deletions
diff --git a/lib/cache/file.php b/lib/cache/file.php
index 9fee6034a71..361138e4736 100644
--- a/lib/cache/file.php
+++ b/lib/cache/file.php
@@ -80,9 +80,11 @@ class OC_Cache_File{
$storage = $this->getStorage();
if($storage and $storage->is_dir('/')) {
$dh=$storage->opendir('/');
- while (($file = readdir($dh)) !== false) {
- if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
- $storage->unlink('/'.$file);
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
+ $storage->unlink('/'.$file);
+ }
}
}
}
@@ -94,6 +96,9 @@ class OC_Cache_File{
if($storage and $storage->is_dir('/')) {
$now = time();
$dh=$storage->opendir('/');
+ if(!is_resource($dh)) {
+ return null;
+ }
while (($file = readdir($dh)) !== false) {
if($file!='.' and $file!='..') {
$mtime = $storage->filemtime('/'.$file);
diff --git a/lib/cache/fileglobal.php b/lib/cache/fileglobal.php
index 2fbd8ca3edb..c0bd8e45f39 100644
--- a/lib/cache/fileglobal.php
+++ b/lib/cache/fileglobal.php
@@ -69,9 +69,11 @@ class OC_Cache_FileGlobal{
$prefix = $this->fixKey($prefix);
if($cache_dir and is_dir($cache_dir)) {
$dh=opendir($cache_dir);
- while (($file = readdir($dh)) !== false) {
- if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
- unlink($cache_dir.$file);
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
+ unlink($cache_dir.$file);
+ }
}
}
}
@@ -88,11 +90,13 @@ class OC_Cache_FileGlobal{
$cache_dir = self::getCacheDir();
if($cache_dir and is_dir($cache_dir)) {
$dh=opendir($cache_dir);
- while (($file = readdir($dh)) !== false) {
- if($file!='.' and $file!='..') {
- $mtime = filemtime($cache_dir.$file);
- if ($mtime < $now) {
- unlink($cache_dir.$file);
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if($file!='.' and $file!='..') {
+ $mtime = filemtime($cache_dir.$file);
+ if ($mtime < $now) {
+ unlink($cache_dir.$file);
+ }
}
}
}