]> git.mjollnir.org Git - moodle.git/commitdiff
added strict context level checks to get_context_instance() MDL-6709 , the reason...
authorskodak <skodak>
Wed, 27 Sep 2006 17:58:17 +0000 (17:58 +0000)
committerskodak <skodak>
Wed, 27 Sep 2006 17:58:17 +0000 (17:58 +0000)
lib/accesslib.php

index 18623d4ac09e1261b2c5fd5b12b9fd361c125d99..dc1a4c5fcd3517a88b3efc6c6d53300419e6f418 100755 (executable)
@@ -1208,16 +1208,24 @@ function validate_context($contextlevel, $instanceid) {
 function get_context_instance($contextlevel=NULL, $instance=SITEID) {
 
     global $context_cache, $context_cache_id, $CONTEXT;
+    static $allowed_contexts = array(CONTEXT_SYSTEM, CONTEXT_PERSONAL, CONTEXT_USER, CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_GROUP, CONTEXT_MODULE, CONTEXT_BLOCK);
 
 /// If no level is supplied then return the current global context if there is one
     if (empty($contextlevel)) {
         if (empty($CONTEXT)) {
-            debugging("Error: get_context_instance() called without a context");
+            //fatal error, code must be fixed
+            error("Error: get_context_instance() called without a context");
         } else {
             return $CONTEXT;
         }
     }
 
+/// check allowed context levels
+    if (!in_array($contextlevel, $allowed_contexts)) {
+        // fatal error, code must be fixed - probably typo or switched parameters 
+        error('Error: get_context_instance() called with incorrect context level "'.s($contextlevel).'"');
+    }
+
 /// Check the cache
     if (isset($context_cache[$contextlevel][$instance])) {  // Already cached
         return $context_cache[$contextlevel][$instance];