Skip to content

Commit

Permalink
[Tobi] Defence in depth if the config option is missing.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmcj committed Oct 4, 2023
1 parent 0ae6b90 commit 8d062ac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
16 changes: 15 additions & 1 deletion webapp/src/Controller/Jury/ExecutableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ public function indexAction(Request $request): Response

$propertyAccessor = PropertyAccess::createPropertyAccessor();
$executables_table = [];
$configScripts = [];
foreach (['compare', 'run', 'full_debug'] as $config_script) {
/* Seems to fail
try {
$configScripts[] = (string)$this->config->get('default_' . $config_script);
} catch (InvalidArgumentException $e) {
// Ignore
}*/
// If not found this is an older database, as we only use this for visual changes ignore this error;
if ($this->config->checkExistance('default_' . $config_script)) {
$configScripts[] = (string)$this->config->get('default_' . $config_script);
}
}

foreach ($executables as $e) {
$execdata = [];
$execactions = [];
Expand Down Expand Up @@ -117,7 +131,7 @@ public function indexAction(Request $request): Response
'link' => $this->generateUrl('jury_executable_download', ['execId' => $e->getExecid()])
];

if ($e->checkEnabled()) {
if ($e->checkEnabled($configScripts)) {
$executables_tables_enabled[] = [
'data' => $execdata,
'actions' => $execactions,
Expand Down
11 changes: 7 additions & 4 deletions webapp/src/Entity/Executable.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,17 @@ public function getZipfileContent(string $tempdir): string
return $zipFileContents;
}

public function checkEnabled(): bool
/**
* @param string[] $configScripts
*/
public function checkEnabled(array $configScripts): bool
{
foreach (['compare', 'run', 'full_debug'] as $config_script) {
if ($execid === (string)$this->config->get('default_' . $config_script)) {
foreach ($configScripts as $config_script) {
if ($this->execid === $config_script) {
return true;
}
}
if (count($problems_compare) || count($problems_run)) {
if (count($this->problems_compare) || count($this->problems_run)) {
return true;
}
return false;
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/Service/ConfigurationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public function get(string $name, bool $onlyIfPublic = false)
return $value;
}

public function checkExistance(string $name): bool
{
try {
$this->get($name);
return true;
} catch (InvalidArgumentException $e) {
return false;
}
}

/**
* Get all the configuration values, indexed by name.
*
Expand Down

0 comments on commit 8d062ac

Please sign in to comment.