Skip to content
Browse files

MDL-27559 opendir: validate directory pointer on open

  • Loading branch information...
1 parent 5a5cdaf commit 80c27aab8c1125483a76f4c004b4bf85c97dde04 @mackensen mackensen committed May 25, 2012
Showing with 26 additions and 8 deletions.
  1. +3 −1 backup/bb/restore_bb.php
  2. +3 −1 backup/util/helper/backup_general_helper.class.php
  3. +4 −1 lib/filelib.php
  4. +8 −3 lib/moodlelib.php
  5. +4 −1 lib/rsslib.php
  6. +4 −1 lib/webdavlib.php
View
4 backup/bb/restore_bb.php
@@ -8,7 +8,9 @@
require_once($CFG->dirroot.'/backup/bb/xsl_emulate_xslt.inc');
function get_subdirs($directory){
- $opendirectory = opendir( $directory );
+ if (!$opendirectory = opendir( $directory )) {
+ return array();
+ }
while(false !== ($filename = readdir($opendirectory))) {
if (is_dir($directory.$filename) and $filename != ".." and $filename != "."){
$subdirs[] = $filename;
View
4 backup/util/helper/backup_general_helper.class.php
@@ -79,7 +79,9 @@ public static function get_blocks_from_path($path) {
return array();
}
- $dir = opendir($path);
+ if (!$dir = opendir($path)) {
+ return array();
+ }
while (false !== ($file = readdir($dir))) {
if ($file == '.' || $file == '..') { // Skip dots
continue;
View
5 lib/filelib.php
@@ -2520,7 +2520,10 @@ function fulldelete($location) {
return false;
}
if (is_dir($location)) {
- $currdir = opendir($location);
+
+ if (!$currdir = opendir($location)) {
+ return false;
+ }
while (false !== ($file = readdir($currdir))) {
if ($file <> ".." && $file <> ".") {
$fullfile = $location."/".$file;
View
11 lib/moodlelib.php
@@ -8005,7 +8005,10 @@ function get_list_of_plugins($directory='mod', $exclude='', $basedir='') {
}
if (file_exists($basedir) && filetype($basedir) == 'dir') {
- $dirhandle = opendir($basedir);
+ if (!$dirhandle = opendir($basedir)) {
+ debugging("Could not open $basedir");
+ return array();
+ }
while (false !== ($dir = readdir($dirhandle))) {
$firstchar = substr($dir, 0, 1);
if ($firstchar === '.' or $dir === 'CVS' or $dir === '_vti_cnf' or $dir === 'simpletest' or $dir === 'yui' or $dir === 'phpunit' or $dir === $exclude) {
@@ -10201,7 +10204,7 @@ function apd_get_profiling() {
}
/**
- * Delete directory or only it's content
+ * Delete directory or only its content
*
* @param string $dir directory path
* @param bool $content_only
@@ -10212,7 +10215,9 @@ function remove_dir($dir, $content_only=false) {
// nothing to do
return true;
}
- $handle = opendir($dir);
+ if (!$handle = opendir($dir)) {
+ return false;
+ }
$result = true;
while (false!==($item = readdir($handle))) {
if($item != '.' && $item != '..') {
View
5 lib/rsslib.php
@@ -110,7 +110,10 @@ function rss_delete_file($componentname, $instance) {
$dirpath = "$CFG->cachedir/rss/$componentname";
if (is_dir($dirpath)) {
- $dh = opendir($dirpath);
+ if (!$dh = opendir($dirpath)) {
+ error_log("Could not open $dirpath");
+ return;
+ }
while (false !== ($filename = readdir($dh))) {
if ($filename!='.' && $filename!='..') {
if (preg_match("/{$instance->id}_/", $filename)) {
View
5 lib/webdavlib.php
@@ -946,7 +946,10 @@ function mput($filelist) {
if ($result) {
// recurse directories
if (is_dir($localpath)) {
- $dp = opendir($localpath);
+ if (!$dp = opendir($localpath)) {
+ error_log("Could not open $localpath");
+ return false;
+ }
$fl = array();
while($filename = readdir($dp)) {
if ((is_file($localpath."/".$filename) || is_dir($localpath."/".$filename)) && $filename!="." && $filename != "..") {

0 comments on commit 80c27aa

Please sign in to comment.
Something went wrong with that request. Please try again.