Skip to content

Commit

Permalink
MDL-38456 Allow colons in paths passed to mdeploy.php utility
Browse files Browse the repository at this point in the history
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 5230f6a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
11 changes: 10 additions & 1 deletion mdeploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 27 additions & 1 deletion mdeploytest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),

Expand All @@ -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
*/
Expand Down

0 comments on commit 5230f6a

Please sign in to comment.