Merge pull request #4719 from owncloud/port_4701_master

Always check variable type before using readdir to avoid surprises
This commit is contained in:
Thomas Müller 2013-09-12 15:44:20 -07:00
commit d5ddbfb045
20 changed files with 215 additions and 171 deletions

View File

@ -329,7 +329,7 @@ class Util {
$this->view->is_dir($directory)
&& $handle = $this->view->opendir($directory)
) {
if(is_resource($handle)) {
while (false !== ($file = readdir($handle))) {
if (
@ -396,6 +396,7 @@ class Util {
}
}
}
\OC_FileProxy::$enabled = true;

View File

@ -183,6 +183,8 @@ class AmazonS3 extends \OC\Files\Storage\Common {
}
$dh = $this->opendir($path);
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file === '.' || $file === '..') {
continue;
@ -194,6 +196,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
$this->unlink($path . '/' . $file);
}
}
}
try {
$result = $this->connection->deleteObject(array(
@ -464,6 +467,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
}
$dh = $this->opendir($path1);
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file === '.' || $file === '..') {
continue;
@ -474,6 +478,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
$this->copy($source, $target);
}
}
}
return true;
}

View File

@ -378,7 +378,7 @@ class OC_Mount_Config {
}
$result = array();
$handle = opendir($path);
if ( ! $handle) {
if(!is_resource($handle)) {
return array();
}
while (false !== ($file = readdir($handle))) {

View File

@ -206,7 +206,8 @@ class Google extends \OC\Files\Storage\Common {
public function rmdir($path) {
if (trim($path, '/') === '') {
$dir = $this->opendir($path);
while (($file = readdir($dh)) !== false) {
if(is_resource($dir)) {
while (($file = readdir($dir)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if (!$this->unlink($path.'/'.$file)) {
return false;
@ -214,6 +215,7 @@ class Google extends \OC\Files\Storage\Common {
}
}
closedir($dir);
}
$this->driveFiles = array();
return true;
} else {

View File

@ -138,6 +138,7 @@ class iRODS extends \OC\Files\Storage\StreamWrapper{
private function collectionMTime($path) {
$dh = $this->opendir($path);
$lastCTime = $this->filemtime($path);
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' and $file != '..') {
$time = $this->filemtime($file);
@ -146,6 +147,7 @@ class iRODS extends \OC\Files\Storage\StreamWrapper{
}
}
}
}
return $lastCTime;
}

View File

@ -99,6 +99,7 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
private function shareMTime() {
$dh=$this->opendir('');
$lastCtime=0;
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file!='.' and $file!='..') {
$ctime=$this->filemtime($file);
@ -107,6 +108,7 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
}
}
}
}
return $lastCtime;
}
}

View File

@ -221,7 +221,8 @@ class Shared extends \OC\Files\Storage\Common {
public function filemtime($path) {
if ($path == '' || $path == '/') {
$mtime = 0;
if ($dh = $this->opendir($path)) {
$dh = $this->opendir($path);
if(is_resource($dh)) {
while (($filename = readdir($dh)) !== false) {
$tempmtime = $this->filemtime($filename);
if ($tempmtime > $mtime) {

View File

@ -23,6 +23,7 @@ if ($dir) {
$dirlisting = true;
$dirContent = $view->opendir($dir);
$i = 0;
if(is_resource($dirContent)) {
while(($entryName = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
$pos = strpos($dir.'/', '/', 1);
@ -39,7 +40,7 @@ if ($dir) {
}
}
closedir($dirContent);
}
} else {
$dirlisting = false;
$query = \OC_DB::prepare('SELECT `id`,`location`,`timestamp`,`type`,`mime` FROM `*PREFIX*files_trash` WHERE `user` = ?');

View File

@ -667,6 +667,7 @@ class OC_App{
}
$dh = opendir( $apps_dir['path'] );
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file[0] != '.' and is_file($apps_dir['path'].'/'.$file.'/appinfo/app.php')) {
@ -676,6 +677,7 @@ class OC_App{
}
}
}
}

View File

@ -119,7 +119,8 @@ abstract class OC_Archive{
* @return bool
*/
function addRecursive($path, $source) {
if($dh=opendir($source)) {
$dh = opendir($source);
if(is_resource($dh)) {
$this->addFolder($path);
while (($file = readdir($dh)) !== false) {
if($file=='.' or $file=='..') {

5
lib/cache/file.php vendored
View File

@ -80,12 +80,14 @@ class OC_Cache_File{
$storage = $this->getStorage();
if($storage and $storage->is_dir('/')) {
$dh=$storage->opendir('/');
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
$storage->unlink('/'.$file);
}
}
}
}
return true;
}
@ -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);

View File

@ -69,6 +69,7 @@ class OC_Cache_FileGlobal{
$prefix = $this->fixKey($prefix);
if($cache_dir and is_dir($cache_dir)) {
$dh=opendir($cache_dir);
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
unlink($cache_dir.$file);
@ -76,6 +77,7 @@ class OC_Cache_FileGlobal{
}
}
}
}
static public function gc() {
$last_run = OC_AppConfig::getValue('core', 'global_cache_gc_lastrun', 0);
@ -88,6 +90,7 @@ class OC_Cache_FileGlobal{
$cache_dir = self::getCacheDir();
if($cache_dir and is_dir($cache_dir)) {
$dh=opendir($cache_dir);
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if($file!='.' and $file!='..') {
$mtime = filemtime($cache_dir.$file);
@ -99,3 +102,4 @@ class OC_Cache_FileGlobal{
}
}
}
}

View File

@ -88,6 +88,7 @@ class ObjectTree extends \Sabre_DAV_ObjectTree {
} else {
Filesystem::mkdir($destination);
$dh = Filesystem::opendir($source);
if(is_resource($dh)) {
while (($subnode = readdir($dh)) !== false) {
if ($subnode == '.' || $subnode == '..') continue;
@ -95,6 +96,7 @@ class ObjectTree extends \Sabre_DAV_ObjectTree {
}
}
}
list($destinationDir,) = \Sabre_DAV_URLUtil::splitPath($destination);
$this->markDirty($destinationDir);

View File

@ -159,6 +159,7 @@ class Scanner extends BasicEmitter {
$newChildren = array();
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
\OC_DB::beginTransaction();
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
$child = ($path) ? $path . '/' . $file : $file;
if (!Filesystem::isIgnoredDir($file)) {
@ -177,6 +178,7 @@ class Scanner extends BasicEmitter {
}
}
}
}
$removedChildren = \array_diff($existingChildren, $newChildren);
foreach ($removedChildren as $childName) {
$child = ($path) ? $path . '/' . $childName : $childName;

View File

@ -142,6 +142,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
return false;
} else {
$directoryHandle = $this->opendir($directory);
if(is_resource($directoryHandle)) {
while (($contents = readdir($directoryHandle)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($contents)) {
$path = $directory . '/' . $contents;
@ -152,6 +153,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
}
}
}
}
if ($empty === false) {
if (!$this->rmdir($directory)) {
return false;
@ -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) {

View File

@ -65,6 +65,7 @@ class MappedLocal extends \OC\Files\Storage\Common{
$logicalPath = $this->mapper->physicalToLogic($physicalPath);
$dh = opendir($physicalPath);
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file === '.' or $file === '..') {
continue;
@ -76,6 +77,7 @@ class MappedLocal extends \OC\Files\Storage\Common{
$file = $this->stripLeading($file);
$files[]= $file;
}
}
\OC\Files\Stream\Dir::register('local-win32'.$path, $files);
return opendir('fakedir://local-win32'.$path);

View File

@ -500,11 +500,13 @@ class View {
} else {
if ($this->is_dir($path1) && ($dh = $this->opendir($path1))) {
$result = $this->mkdir($path2);
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if (!Filesystem::isIgnoredDir($file)) {
$result = $this->copy($path1 . '/' . $file, $path2 . '/' . $file);
}
}
}
} else {
$source = $this->fopen($path1 . $postFix1, 'r');
$target = $this->fopen($path2 . $postFix2, 'w');

View File

@ -349,6 +349,7 @@ class OC_Helper {
if (!is_dir($path))
return chmod($path, $filemode);
$dh = opendir($path);
if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..') {
$fullpath = $path . '/' . $file;
@ -360,6 +361,7 @@ class OC_Helper {
}
}
closedir($dh);
}
if (@chmod($path, $filemode))
return true;
else
@ -657,11 +659,13 @@ class OC_Helper {
// if oc-noclean is empty delete it
$isTmpDirNoCleanEmpty = true;
$tmpDirNoClean = opendir($tmpDirNoCleanName);
if(is_resource($tmpDirNoClean)) {
while (false !== ($file = readdir($tmpDirNoClean))) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
$isTmpDirNoCleanEmpty = false;
}
}
}
if ($isTmpDirNoCleanEmpty) {
rmdir($tmpDirNoCleanName);
}

View File

@ -107,6 +107,7 @@ class OC_Installer{
if(!is_file($extractDir.'/appinfo/info.xml')) {
//try to find it in a subdir
$dh=opendir($extractDir);
if(is_resource($dh)) {
while (($folder = readdir($dh)) !== false) {
if($folder[0]!='.' and is_dir($extractDir.'/'.$folder)) {
if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')) {
@ -115,6 +116,7 @@ class OC_Installer{
}
}
}
}
if(!is_file($extractDir.'/appinfo/info.xml')) {
OC_Helper::rmdirr($extractDir);
if($data['source']=='http') {

View File

@ -191,7 +191,8 @@ class OC_Migration_Content{
if( !file_exists( $dir ) ) {
return false;
}
if ($dirhandle = opendir($dir)) {
$dirhandle = opendir($dir);
if(is_resource($dirhandle)) {
while (false !== ( $file = readdir($dirhandle))) {
if (( $file != '.' ) && ( $file != '..' )) {