diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2013-09-04 13:06:04 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2013-09-04 13:06:04 +0200 |
commit | ec3639dc7a28348b136d2008e692cffe8c3753ad (patch) | |
tree | 3d197d325496925be0ddee1f1ab22c48c7c817a1 /lib/cache | |
parent | 09187f3b3b30e6f810c6afff7332615ed472154e (diff) | |
download | nextcloud-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.php | 11 | ||||
-rw-r--r-- | lib/cache/fileglobal.php | 20 |
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); + } } } } |