diff --git a/classes/external/run_in_sandbox.php b/classes/external/run_in_sandbox.php index 7e2475af4..82738bccf 100644 --- a/classes/external/run_in_sandbox.php +++ b/classes/external/run_in_sandbox.php @@ -111,9 +111,9 @@ public static function execute($contextid, $sourcecode, $language='python3', throw new qtype_coderunner_exception(get_string('wsnoaccess', 'qtype_coderunner')); } - $sandbox = qtype_coderunner_sandbox::get_best_sandbox($language); + $sandbox = qtype_coderunner_sandbox::get_best_sandbox($language, true); if ($sandbox === null) { - throw new qtype_coderunner_exception("Language {$language} is not available on this system"); + throw new qtype_coderunner_exception(get_string('wsnolanguage', 'qtype_coderunner', $language)); } if (get_config('qtype_coderunner', 'wsloggingenabled')) { @@ -139,8 +139,13 @@ public static function execute($contextid, $sourcecode, $language='python3', } try { - $filesarray = $files ? json_decode($files, true) : null; + $filesarray = $files ? json_decode($files, true) : array(); $paramsarray = $params ? json_decode($params, true) : array(); + + // Throws error for incorrect JSON formatting + if ($filesarray === null || $paramsarray === null) { + throw new qtype_coderunner_exception(get_string('wsbadjson', 'qtype_coderunner')); + } $maxcputime = intval(get_config('qtype_coderunner', 'wsmaxcputime')); // Limit CPU time through this service. if (isset($paramsarray['cputime'])) { $paramsarray['cputime'] = min($paramsarray['cputime'], $maxcputime); diff --git a/lang/en/qtype_coderunner.php b/lang/en/qtype_coderunner.php index d800c3bcf..103c6175d 100644 --- a/lang/en/qtype_coderunner.php +++ b/lang/en/qtype_coderunner.php @@ -1221,14 +1221,16 @@ function should be applied, e.g. {{STUDENT_ANSWER | e(\'py\')}} is $string['validateonsave'] = 'Validate on save'; $string['wrongnumberofformats'] = 'Wrong number of test results column formats. Expected {$a->expected}, got {$a->got}'; +$string['wsbadjson'] = 'params and file parameters must be blank or a valid JSON record'; $string['wsdisabled'] = 'Sandbox web service disabled. Talk to a sysadmin'; $string['wsloggingenable'] = 'Log sandbox web service usage'; $string['wsloggingenable_desc'] = 'If this option is checked, every code execution via the sandbox web service will be logged. This option must be enabled if user rate throttling is to work.'; -$string['wsnoaccess'] = 'Only logged-in non-guest users can access this functionality'; $string['wsmaxcputime'] = 'Max CPU time (secs)'; $string['wsmaxcputime_desc'] = 'Limits the maximum CPU time that a web service job can use, even if it explicitly sets the CPU time sandbox parameter.'; $string['wsmaxhourlyrate'] = 'Max hourly rate of submissions'; $string['wsmaxhourlyrate_desc'] = 'If a user attempts to exceed this rate of submissions in any given hour their submissions will be disallowed. 0 for no rate throttling. Requires that logging of web service usage be enabled.'; +$string['wsnoaccess'] = 'Only logged-in non-guest users can access this functionality'; +$string['wsnolanguage'] = 'Language "{$a}" is not known'; $string['wssubmissionrateexceeded'] = 'You have exceeded the maximum hourly \'Try it!\' submission rate. Request denied.'; $string['xmlcoderunnerformaterror'] = 'XML format error in coderunner question';