Skip to content

Commit

Permalink
MDL-27559 opendir: validate directory pointer on open
Browse files Browse the repository at this point in the history
  • Loading branch information
mackensen committed May 25, 2012
1 parent 5a5cdaf commit 80c27aa
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
4 changes: 3 additions & 1 deletion backup/bb/restore_bb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion backup/util/helper/backup_general_helper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion lib/filelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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 != '..') {
Expand Down
5 changes: 4 additions & 1 deletion lib/rsslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
5 changes: 4 additions & 1 deletion lib/webdavlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "..") {
Expand Down

0 comments on commit 80c27aa

Please sign in to comment.