From 7a3888a3673f61ce7f32544985a309064097d65e Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 20 Dec 2013 13:31:08 +0100 Subject: [PATCH] Prevent copy of trees that does not exist. --- h5p.classes.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index b17d33e..ff7b72a 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1109,7 +1109,9 @@ Class H5PExport { @mkdir($tempPath); $exportData = $this->h5pF->getExportData($contentId); // Create content folder - $this->h5pC->copyTree($h5pDir . 'content' . DIRECTORY_SEPARATOR . $contentId, $tempPath . DIRECTORY_SEPARATOR . 'content'); + if ($this->h5pC->copyTree($h5pDir . 'content' . DIRECTORY_SEPARATOR . $contentId, $tempPath . DIRECTORY_SEPARATOR . 'content') === FALSE) { + return FALSE; + } file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . 'content.json', $exportData['jsonContent']); // Make embedTypes into an array @@ -1307,6 +1309,12 @@ class H5PCore { */ public function copyTree($source, $destination) { $dir = opendir($source); + + if ($dir === FALSE) { + $this->h5pF->setErrorMessage($this->h5pF->t('Unable to copy tree, no such directory: @dir', array('@dir' => $source))); + return FALSE; + } + @mkdir($destination); while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..')) {