MDL-49087 mnet: Ensure typeroot is in dirroot

This commit is contained in:
Andrew Nicols 2015-02-13 14:06:31 +08:00 committed by Eloy Lafuente (stronk7)
parent 9b92620ff1
commit 2820930f57
2 changed files with 12 additions and 1 deletions

View File

@ -736,6 +736,7 @@ class worker extends singleton_pattern {
/** @var array the whitelisted config options which can be queried. */
private $validconfigoptions = array(
'dirroot' => true,
'dataroot' => true,
);
@ -781,8 +782,13 @@ class worker extends singleton_pattern {
}
$this->log('MD5 checksum ok');
// Backup the current version of the plugin
// Check that the specified typeroot is within the current site's dirroot.
$plugintyperoot = $this->input->get_option('typeroot');
if (strpos(realpath($plugintyperoot), realpath($this->get_env('dirroot'))) !== 0) {
throw new backup_folder_exception('Unable to backup the current version of the plugin (typeroot is invalid)');
}
// Backup the current version of the plugin
$pluginname = $this->input->get_option('name');
$sourcelocation = $plugintyperoot.'/'.$pluginname;
$backuplocation = $this->backup_location($sourcelocation);
@ -826,6 +832,10 @@ class worker extends singleton_pattern {
$source = $this->input->get_option('package');
$md5remote = $this->input->get_option('md5');
if (strpos(realpath($plugintyperoot), realpath($this->get_env('dirroot'))) !== 0) {
throw new backup_folder_exception('Unable to prepare the plugin location (typeroot is invalid)');
}
// Check if the plugin location if available for us.
$pluginlocation = $plugintyperoot.'/'.$pluginname;

View File

@ -364,6 +364,7 @@ class mdeploytest extends PHPUnit_Framework_TestCase {
public function get_env_valid_provider() {
return array(
array('dataroot'),
array('dirroot'),
);
}
}