|
|
@@ -6,6 +6,17 @@
|
|
|
become404Page();
|
|
|
}
|
|
|
|
|
|
+ // $_POST['result'] is attacker-controllable whenever the judger password is
|
|
|
+ // weak or leaked (the repo used to ship a placeholder), so decode it once
|
|
|
+ // and refuse anything that is not an object.
|
|
|
+ function judgeResultFromPost() {
|
|
|
+ $result = json_decode($_POST['result'] ?? '', true);
|
|
|
+ if (!is_array($result)) {
|
|
|
+ die("Wow! hacker! T_T....");
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
function submissionJudged() {
|
|
|
$submission = DB::selectFirst("select submitter, status, content, result, problem_id from submissions where id = {$_POST['id']}");
|
|
|
if ($submission == null) {
|
|
|
@@ -18,7 +29,7 @@
|
|
|
|
|
|
if (isset($content['first_test_config'])) {
|
|
|
$result = json_decode($submission['result'], true);
|
|
|
- $result['final_result'] = json_decode($_POST['result'], true);
|
|
|
+ $result['final_result'] = judgeResultFromPost();
|
|
|
$result['final_result']['details'] = uojTextEncode($result['final_result']['details']);
|
|
|
$esc_result = DB::escape(json_encode($result, JSON_UNESCAPED_UNICODE));
|
|
|
|
|
|
@@ -29,13 +40,20 @@
|
|
|
|
|
|
DB::update("update submissions set status = 'Judged', result = '$esc_result', content = '$esc_content' where id = {$_POST['id']}");
|
|
|
} else {
|
|
|
- $result = json_decode($_POST['result'], true);
|
|
|
+ $result = judgeResultFromPost();
|
|
|
$result['details'] = uojTextEncode($result['details']);
|
|
|
$esc_result = DB::escape(json_encode($result, JSON_UNESCAPED_UNICODE));
|
|
|
+ // status/result_error are varchar and score/used_* are int, so
|
|
|
+ // escape the former and cast the latter.
|
|
|
+ $status = DB::escape($result['status']);
|
|
|
if (isset($result["error"])) {
|
|
|
- DB::update("update submissions set status = '{$result['status']}', result_error = '{$result['error']}', result = '$esc_result', score = null, used_time = null, used_memory = null where id = {$_POST['id']}");
|
|
|
+ $error = DB::escape($result['error']);
|
|
|
+ DB::update("update submissions set status = '$status', result_error = '$error', result = '$esc_result', score = null, used_time = null, used_memory = null where id = {$_POST['id']}");
|
|
|
} else {
|
|
|
- DB::update("update submissions set status = '{$result['status']}', result_error = null, result = '$esc_result', score = {$result['score']}, used_time = {$result['time']}, used_memory = {$result['memory']} where id = {$_POST['id']}");
|
|
|
+ $score = (int)$result['score'];
|
|
|
+ $time = (int)$result['time'];
|
|
|
+ $memory = (int)$result['memory'];
|
|
|
+ DB::update("update submissions set status = '$status', result_error = null, result = '$esc_result', score = $score, used_time = $time, used_memory = $memory where id = {$_POST['id']}");
|
|
|
}
|
|
|
|
|
|
if (isset($content['final_test_config'])) {
|
|
|
@@ -60,21 +78,23 @@
|
|
|
return;
|
|
|
}
|
|
|
$content = json_decode($submission['content'], true);
|
|
|
- $result = json_decode($_POST['result'], true);
|
|
|
+ $result = judgeResultFromPost();
|
|
|
$result['details'] = uojTextEncode($result['details']);
|
|
|
$esc_result = DB::escape(json_encode($result, JSON_UNESCAPED_UNICODE));
|
|
|
+ $status = DB::escape($result['status']);
|
|
|
if (isset($result["error"])) {
|
|
|
- DB::update("update custom_test_submissions set status = '{$result['status']}', result = '$esc_result' where id = {$_POST['id']}");
|
|
|
+ DB::update("update custom_test_submissions set status = '$status', result = '$esc_result' where id = {$_POST['id']}");
|
|
|
} else {
|
|
|
- DB::update("update custom_test_submissions set status = '{$result['status']}', result = '$esc_result' where id = {$_POST['id']}");
|
|
|
+ DB::update("update custom_test_submissions set status = '$status', result = '$esc_result' where id = {$_POST['id']}");
|
|
|
}
|
|
|
DB::update("update custom_test_submissions set status_details = '' where id = {$_POST['id']}");
|
|
|
}
|
|
|
|
|
|
function hackJudged() {
|
|
|
- $result = json_decode($_POST['result'], true);
|
|
|
+ $result = judgeResultFromPost();
|
|
|
$esc_details = DB::escape(uojTextEncode($result['details']));
|
|
|
- $ok = DB::update("update hacks set success = {$result['score']}, details = '$esc_details' where id = {$_POST['id']}");
|
|
|
+ $success = (int)$result['score'];
|
|
|
+ $ok = DB::update("update hacks set success = $success, details = '$esc_details' where id = {$_POST['id']}");
|
|
|
|
|
|
if ($ok) {
|
|
|
list($hack_input) = DB::fetch(DB::query("select input from hacks where id = {$_POST['id']}"), MYSQLI_NUM);
|