Skip to content

Commit

Permalink
MDL-64497 GDPR: moodle_content_writer can cause endless loop
Browse files Browse the repository at this point in the history
Fixes a buggy function by replacing it with a call to file_get_contents,
and adds error detection on a couple of file accesses.
  • Loading branch information
sammarshallou committed Jan 3, 2019
1 parent 38a1b4f commit fc570e6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions privacy/classes/local/request/moodle_content_writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,14 @@ protected function get_files_target_url($component, $filearea, $itemid) : string
*
* @param string $path The path to export the data at.
* @param string $data The data to be exported.
* @throws \moodle_exception If the file cannot be written for some reason.
*/
protected function write_data(string $path, string $data) {
$targetpath = $this->path . DIRECTORY_SEPARATOR . $path;
check_dir_exists(dirname($targetpath), true, true);
file_put_contents($targetpath, $data);
if (file_put_contents($targetpath, $data) === false) {
throw new \moodle_exception('cannotsavefile', 'error', '', $targetpath);
}
$this->files[$path] = $targetpath;
}

Expand Down Expand Up @@ -706,12 +709,12 @@ protected function condense_array(array $array) : Array {
*
* @param string $filepath The file path.
* @return string contents of the file.
* @throws \moodle_exception If the file cannot be opened.
*/
protected function get_file_content(string $filepath) : String {
$filepointer = fopen($filepath, 'r');
$content = '';
while (!feof($filepointer)) {
$content .= fread($filepointer, filesize($filepath));
$content = file_get_contents($filepath);
if ($content === false) {
throw new \moodle_exception('cannotopenfile', 'error', '', $filepath);
}
return $content;
}
Expand Down

0 comments on commit fc570e6

Please sign in to comment.