Permalink
Browse files

MDL-36094 cache: Fixed up inclusion path for overrideclassfile and da…

…tasourcefile
  • Loading branch information...
1 parent 7e8ae12 commit e0a568e281235fbe80103756866b26ab410a73a4 Sam Hemelryk committed Oct 17, 2012
Showing with 20 additions and 4 deletions.
  1. +16 −2 cache/classes/definition.php
  2. +4 −2 cache/tests/cache_test.php
@@ -265,6 +265,8 @@ class cache_definition {
* @throws coding_exception
*/
public static function load($id, array $definition, $datasourceaggregate = null) {
+ global $CFG;
+
if (!array_key_exists('mode', $definition)) {
throw new coding_exception('You must provide a mode when creating a cache definition');
}
@@ -349,6 +351,12 @@ public static function load($id, array $definition, $datasourceaggregate = null)
if (!is_null($overrideclass)) {
if (!is_null($overrideclassfile)) {
+ if (strpos($overrideclassfile, $CFG->dirroot) !== 0) {
+ $overrideclassfile = $CFG->dirroot.'/'.$overrideclassfile;
+ }
+ if (strpos($overrideclassfile, '../') !== false) {
+ throw new coding_exception('No path craziness allowed within override class file path.');
+ }
if (!file_exists($overrideclassfile)) {
throw new coding_exception('The override class file does not exist.');
}
@@ -366,13 +374,19 @@ public static function load($id, array $definition, $datasourceaggregate = null)
if (!is_null($datasource)) {
if (!is_null($datasourcefile)) {
+ if (strpos($datasourcefile, $CFG->dirroot) !== 0) {
+ $datasourcefile = $CFG->dirroot.'/'.$datasourcefile;
+ }
+ if (strpos($datasourcefile, '../') !== false) {
+ throw new coding_exception('No path craziness allowed within data source file path.');
+ }
if (!file_exists($datasourcefile)) {
- throw new coding_exception('The override class file does not exist.');
+ throw new coding_exception('The data source class file does not exist.');
}
require_once($datasourcefile);
}
if (!class_exists($datasource)) {
- throw new coding_exception('The override class does not exist.');
+ throw new coding_exception('The data source class does not exist.');
}
if (!array_key_exists('cache_data_source', class_implements($datasource))) {
throw new coding_exception('Cache data source classes must implement the cache_data_source interface');
@@ -319,7 +319,8 @@ public function test_definition_data_loader() {
'mode' => cache_store::MODE_APPLICATION,
'component' => 'phpunit',
'area' => 'datasourcetest',
- 'datasource' => 'cache_phpunit_dummy_datasource'
+ 'datasource' => 'cache_phpunit_dummy_datasource',
+ 'datasourcefile' => 'cache/tests/fixtures/lib.php'
));
$cache = cache::make('phpunit', 'datasourcetest');
@@ -347,7 +348,8 @@ public function test_definition_overridden_loader() {
'mode' => cache_store::MODE_APPLICATION,
'component' => 'phpunit',
'area' => 'overridetest',
- 'overrideclass' => 'cache_phpunit_dummy_overrideclass'
+ 'overrideclass' => 'cache_phpunit_dummy_overrideclass',
+ 'overrideclassfile' => 'cache/tests/fixtures/lib.php'
));
$cache = cache::make('phpunit', 'overridetest');
$this->assertInstanceOf('cache_phpunit_dummy_overrideclass', $cache);

0 comments on commit e0a568e

Please sign in to comment.