MDL-46148 qtype_calculated: low-level defence against bad formulas
This catches things like: * Malicious equations coming from backup files. * Malicious equations in old questions in the database.
This commit is contained in:
committed by
Damyon Wiese
parent
f2946a5419
commit
82b3260eab
@@ -419,6 +419,10 @@ class qtype_calculated_variable_substituter {
|
||||
* @return float the computed result.
|
||||
*/
|
||||
public function calculate($expression) {
|
||||
// Make sure no malicious code is present in the expression. Refer MDL-46148 for details.
|
||||
if ($error = qtype_calculated_find_formula_errors($expression)) {
|
||||
throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '', $error);
|
||||
}
|
||||
return $this->calculate_raw($this->substitute_values_for_eval($expression));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user