Skip to content

Commit 82b3260

Browse files
ankitagarwalDamyon Wiese
authored and
Damyon Wiese
committed
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.
1 parent f2946a5 commit 82b3260

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Diff for: question/type/calculated/question.php

+4
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ public function get_values() {
419419
* @return float the computed result.
420420
*/
421421
public function calculate($expression) {
422+
// Make sure no malicious code is present in the expression. Refer MDL-46148 for details.
423+
if ($error = qtype_calculated_find_formula_errors($expression)) {
424+
throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '', $error);
425+
}
422426
return $this->calculate_raw($this->substitute_values_for_eval($expression));
423427
}
424428

0 commit comments

Comments
 (0)