Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added checks if request parameters are numeric to prevent command injections #40

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions application/libraries/LanguageTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ public function run_in_sandbox($wrappedCmd, $iscompile=true, $stdin=null) {
$filesize = 1000 * $this->getParam('disklimit', $iscompile); // MB -> kB
$streamsize = 1000 * $this->getParam('streamsize', $iscompile); // MB -> kB
$memsize = 1000 * $this->getParam('memorylimit', $iscompile);
$cputime = $this->getParam('cputime', $iscompile);
$cputime = $this->check_integer($this->getParam('cputime', $iscompile), $this->default_params['cputime']);
$killtime = 2 * $cputime; // Kill the job after twice the allowed cpu time
$numProcs = $this->getParam('numprocs', $iscompile) + 1; // The + 1 allows for the sh command below.
$numProcs = $this->check_integer(($this->getParam('numprocs', $iscompile) + 1), $this->default_params['numprocs']); // The + 1 allows for the sh command below.
$sandboxCommandBits = array(
"sudo " . dirname(__FILE__) . "/../../runguard/runguard",
"--user={$this->user}",
Expand Down Expand Up @@ -321,6 +321,18 @@ public function run_in_sandbox($wrappedCmd, $iscompile=true, $stdin=null) {
return array($output, $stderr);
}

/*
* Checks if the $key parameter is numeric and returns it,
* otherwise it will return the $fallbackInt parameter.
*/
private function check_integer($key, $fallbackInt) {
if(is_numeric($key)) {
return $key;
} else {
return $fallbackInt;
}
}


/*
* Get the value of the job parameter $key, which is taken from the
Expand Down