function safe_command($working_dir, $cmd, $args, $limits, $error_out = NULL) { // not on windows if (SystemUtil::is_windows()) { echo "Security Warning: Runguard doesn't work on windows!\n"; return SystemUtil::run_command($working_dir, $cmd, $args, $error_out); } // build command $actual_cmd = RUNGUARD_PATH; $actual_args = array(); // time limit $actual_args[] = "--time=" . (isset($limits['time limit']) ? $limits['time limit'] : 60); // memory limit if (isset($limits['memory limit'])) { $actual_args[] = "--memsize=" . intval($limits['memory limit'] / 1024); } // filesize limit if (isset($limits['filesize limit'])) { $actual_args[] = "--filesize=" . intval($limits['filesize limit'] / 1024); } // process limit if (isset($limits['process limit'])) { $actual_args[] = "--nproc=" . $limits['process limit']; } // no coredumps $actual_args[] = "--no-core"; // user if (isset($limits['as nobody']) && RUNGUARD_USER !== false) { $actual_args[] = "--user=" . RUNGUARD_USER; } // run $actual_args[] = $cmd; $actual_args = array_merge($actual_args, $args); return SystemUtil::run_command($working_dir, $actual_cmd, $actual_args, $error_out); }
protected function check_case($case) { // checker $checker = $this->entity->checker(); $checker = getcwd() . "/checkers/{$checker}.sh"; $flags = $this->entity->checker_flags(); // the files $case_ref = $this->entity->testcase_reference_output($case); $case_my = $this->tempdir->file("{$case}.out"); $case_diff = $this->tempdir->file("{$case}.diff"); make_file_writable($case_diff); if (!file_exists($case_ref)) { throw new Exception("Reference implementation does not exists:\n{$case_ref}"); } // run checker $result = SystemUtil::run_command($this->tempdir->dir, $checker, array($case_my, $case_ref, $case_diff, $flags)); if (!$result) { $this->put_tempfile("{$case}.diff"); echo " Output does not match\n"; } return $result; }