Skip to content

Commit

Permalink
MDL-46148 qtype_calculated: low-level defence against bad formulas
Browse files Browse the repository at this point in the history
This catches things like:
 * Malicious equations coming from backup files.
 * Malicious equations in old questions in the database.
  • Loading branch information
ankitagarwal authored and Damyon Wiese committed Jul 10, 2014
1 parent 5c74e0d commit 72d8a0a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions question/type/calculated/question.php
Expand Up @@ -419,6 +419,10 @@ public function get_values() {
* @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));
}

Expand Down

0 comments on commit 72d8a0a

Please sign in to comment.