Skip to content
Permalink
Browse files

MDL-38456 Allow colons in paths passed to mdeploy.php utility

The input_manager now accepts colons (:) in TYPE_PATH options, but only
in cases where the colon is used as a part of Windows drive labels, as
in C:\apache.
  • Loading branch information
mudrd8mz committed Mar 13, 2013
1 parent 8673a98 commit 5230f6a7200628f61c154c102d0bedd0192e36af
Showing with 37 additions and 2 deletions.
  1. +10 −1 mdeploy.php
  2. +27 −1 mdeploytest.php
@@ -264,8 +264,17 @@ public function cast_value($raw, $type) {
if (strpos($raw, '~') !== false) {
throw new invalid_option_exception('Using the tilde (~) character in paths is not supported');
}
$colonpos = strpos($raw, ':');
if ($colonpos !== false) {
if ($colonpos !== 1 or strrpos($raw, ':') !== 1) {
throw new invalid_option_exception('Using the colon (:) character in paths is supported for Windows drive labels only.');
}
if (preg_match('/^[a-zA-Z]:/', $raw) !== 1) {
throw new invalid_option_exception('Using the colon (:) character in paths is supported for Windows drive labels only.');
}
}
$raw = str_replace('\\', '/', $raw);
$raw = preg_replace('~[[:cntrl:]]|[&<>"`\|\':]~u', '', $raw);
$raw = preg_replace('~[[:cntrl:]]|[&<>"`\|\']~u', '', $raw);
$raw = preg_replace('~\.\.+~', '', $raw);
$raw = preg_replace('~//+~', '/', $raw);
$raw = preg_replace('~/(\./)+~', '/', $raw);
@@ -144,7 +144,9 @@ public function data_for_cast_value() {
array('0', input_manager::TYPE_FLAG, true),
array('muhehe', input_manager::TYPE_FLAG, true),

array('C:\\WINDOWS\\user.dat', input_manager::TYPE_PATH, 'C/WINDOWS/user.dat'),
array('C:\\WINDOWS\\user.dat', input_manager::TYPE_PATH, 'C:/WINDOWS/user.dat'),
array('D:\xampp\htdocs\24_integration/mdeploy.php', input_manager::TYPE_PATH, 'D:/xampp/htdocs/24_integration/mdeploy.php'),
array('d:/xampp/htdocs/24_integration/mdeploy.php', input_manager::TYPE_PATH, 'd:/xampp/htdocs/24_integration/mdeploy.php'),
array('../../../etc/passwd', input_manager::TYPE_PATH, '/etc/passwd'),
array('///////.././public_html/test.php', input_manager::TYPE_PATH, '/public_html/test.php'),

@@ -163,6 +165,30 @@ public function data_for_cast_value() {
);
}

/**
* @expectedException invalid_option_exception
*/
public function test_input_type_path_multiple_colons() {
$input = testable_input_manager::instance();
$input->cast_value('C:\apache\log:file', input_manager::TYPE_PATH); // must throw exception
}

/**
* @expectedException invalid_option_exception
*/
public function test_input_type_path_invalid_drive_label() {
$input = testable_input_manager::instance();
$input->cast_value('0:/srv/moodledata', input_manager::TYPE_PATH); // must throw exception
}

/**
* @expectedException invalid_option_exception
*/
public function test_input_type_path_invalid_colon() {
$input = testable_input_manager::instance();
$input->cast_value('/var/www/moodle:2.5', input_manager::TYPE_PATH); // must throw exception
}

/**
* @expectedException invalid_coding_exception
*/

0 comments on commit 5230f6a

Please sign in to comment.
You can’t perform that action at this time.