Skip to content

Commit

Permalink
Add support for validation for db config values.
Browse files Browse the repository at this point in the history
Add validation to all integer fields and to timelimit_overshoot.
This fixes #2227.
  • Loading branch information
nickygerritsen committed Nov 24, 2023
1 parent a5f0b40 commit a7571aa
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 38 deletions.
68 changes: 68 additions & 0 deletions etc/db-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
default_value: 20
public: true
description: Penalty time in minutes per wrong submission (if eventually solved).
constraint: Range
constraint_arguments:
min: 0
- name: results_prio
type: array_keyval
default_value:
Expand Down Expand Up @@ -47,56 +50,87 @@
default_value: 2097152
public: false
description: Maximum memory usage (in kB) by submissions. This includes the shell which starts the compiled solution and also any interpreter like the Java VM, which takes away approx. 300MB! Can be overridden per problem.
constraint: Range
constraint_arguments:
min: 1
- name: output_limit
type: int
default_value: 8192
public: false
description: Maximum output (in kB) submissions may generate. Any excessive output is truncated, so this should be greater than the maximum testdata output. Can be overridden per problem.
constraint: Range
constraint_arguments:
min: 1
- name: process_limit
type: int
default_value: 64
public: false
description: Maximum number of processes that the submission is allowed to start (including shell and possibly interpreters).
constraint: Range
constraint_arguments:
min: 1
- name: sourcesize_limit
type: int
default_value: 256
public: true
description: Maximum source code size (in kB) of a submission.
constraint: Range
constraint_arguments:
min: 1
- name: sourcefiles_limit
type: int
default_value: 100
public: true
description: Maximum number of source files in one submission. Set to `1` to disable multi-file submissions.
constraint: Range
constraint_arguments:
min: 1
- name: script_timelimit
type: int
default_value: 30
public: false
description: Maximum seconds available for compile/compare scripts. This is a safeguard against malicious code and buggy scripts, so a reasonable but large amount should do.
constraint: Range
constraint_arguments:
min: 1
- name: script_memory_limit
type: int
default_value: 2097152
public: false
description: Maximum memory usage (in kB) by compile/compare scripts. This is a safeguard against malicious code and buggy script, so a reasonable but large amount should do.
constraint: Range
constraint_arguments:
min: 1
- name: script_filesize_limit
type: int
default_value: 2621440
public: false
description: Maximum filesize (in kB) compile/compare scripts may write. Submission will fail with compiler-error when trying to write more, so this should be greater than any **intermediate or final** result written by compilers.
constraint: Range
constraint_arguments:
min: 1
- name: timelimit_overshoot
type: string
default_value: 1s|10%
public: false
description: Time that submissions are kept running beyond timelimit before being killed. Specify as `Xs` for X seconds, `Y%` as percentage, or a combination of both separated by one of `+|&` for the sum, maximum, or minimum of both.
constraint: TimelimitOvershoot
- name: output_storage_limit
type: int
default_value: 50000
public: false
description: Maximum size of error/system output stored in the database (in bytes); use `-1` to disable any limits.
constraint: Range
constraint_arguments:
min: 1
- name: output_display_limit
type: int
default_value: 2000
public: false
description: Maximum size of run/diff/error/system output shown in the jury interface (in bytes); use `-1` to disable any limits.
constraint: Range
constraint_arguments:
min: 1
- name: lazy_eval_results
type: int
default_value: 1
Expand All @@ -106,21 +140,34 @@
1: Lazy
2: Full judging
3: Only on request
constraint: Range
constraint_arguments:
min: 1
max: 3
- name: judgehost_warning
type: int
default_value: 30
public: false
description: Time in seconds after a judgehost last checked in before showing its status as `warning`.
constraint: Range
constraint_arguments:
min: 1
- name: judgehost_critical
type: int
default_value: 120
public: false
description: Time in seconds after a judgehost last checked in before showing its status as `critical`.
constraint: Range
constraint_arguments:
min: 1
- name: diskspace_error
type: int
default_value: 1048576
public: false
description: Minimum free disk space (in kB) on judgehosts before posting an internal error.
constraint: Range
constraint_arguments:
min: 0
- name: default_compare
type: string
default_value: compare
Expand Down Expand Up @@ -210,6 +257,10 @@
0: never
1: only on compilation error(s)
2: always
constraint: Range
constraint_arguments:
min: 0
max: 2
- name: show_sample_output
type: bool
default_value: false
Expand Down Expand Up @@ -240,6 +291,9 @@
default_value: 200
public: false
description: Maximum width/height of a thumbnail for uploaded testcase images.
constraint: Range
constraint_arguments:
min: 0
- name: show_limits_on_team_page
type: bool
default_value: true
Expand All @@ -259,6 +313,9 @@
default_value: 0
public: false
description: Maximum width of team column on scoreboard. Leave `0` for no maximum.
constraint: Range
constraint_arguments:
min: 0
- name: show_public_stats
type: bool
default_value: true
Expand All @@ -278,6 +335,10 @@
0: Always
1: After login
2: After first submission
constraint: Range
constraint_arguments:
min: 0
max: 2
- category: Authentication
description: Options related to authentication.
items:
Expand Down Expand Up @@ -319,6 +380,10 @@
0: all local
1: configuration data external
2: configuration and live data external
constraint: Range
constraint_arguments:
min: 0
max: 2
docdescription: See :doc:`the chapter on running DOMjudge as a shadow system<shadow>` for more information.
- name: external_contest_sources_allow_untrusted_certificates
type: bool
Expand Down Expand Up @@ -349,6 +414,9 @@
default_value: 120
public: false
description: Time in seconds after an external contest source reader last checked in before showing its status as `critical`.
constraint: Range
constraint_arguments:
min: 0
- name: adminer_enabled
type: bool
default_value: false
Expand Down
19 changes: 17 additions & 2 deletions webapp/src/Controller/API/GeneralInfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,31 @@ public function getDatabaseConfigurationAction(
description: 'The full configuration after change',
content: new OA\JsonContent(type: 'object')
)]
#[OA\Response(
response: 400,
description: 'An error occurred while saving the configuration',
content: new OA\JsonContent(
properties: [
new OA\Property(
property: 'errors',
type: 'object'
)
]
)
)]
#[OA\RequestBody(
required: true,
content: [
new OA\MediaType(mediaType: 'application/x-www-form-urlencoded'),
new OA\MediaType(mediaType: 'application/json'),
]
)]
public function updateConfigurationAction(Request $request): array
public function updateConfigurationAction(Request $request): JsonResponse|array
{
$this->config->saveChanges($request->request->all(), $this->eventLogService, $this->dj);
$errors = $this->config->saveChanges($request->request->all(), $this->eventLogService, $this->dj);
if (!empty($errors)) {
return new JsonResponse(['errors' => $errors], 400);
}
return $this->config->all(false);
}

Expand Down
22 changes: 17 additions & 5 deletions webapp/src/Controller/Jury/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public function indexAction(EventLogService $eventLogService, Request $request):
->getQuery()
->getResult();
if ($request->getMethod() == 'POST' && $request->request->has('save')) {
$this->addFlash('scoreboard_refresh', 'After changing specific ' .
'settings, you might need to refresh the scoreboard.');

$data = [];
foreach ($request->request->all() as $key => $value) {
if (str_starts_with($key, 'config_')) {
Expand All @@ -65,8 +62,17 @@ public function indexAction(EventLogService $eventLogService, Request $request):
}
}
}
$this->config->saveChanges($data, $eventLogService, $this->dj);
return $this->redirectToRoute('jury_config');
$errors = $this->config->saveChanges($data, $eventLogService, $this->dj, $options);

if (empty($errors)) {
$this->addFlash('scoreboard_refresh', 'After changing specific ' .
'settings, you might need to refresh the scoreboard.');

return $this->redirectToRoute('jury_config');
} else {
$this->addFlash('danger', 'Some errors occurred while saving configuration, ' .
'please check the data you entered.');
}
}

$categories = [];
Expand All @@ -76,12 +82,16 @@ public function indexAction(EventLogService $eventLogService, Request $request):
}
}
$allData = [];
$activeCategory = null;
foreach ($categories as $category) {
$data = [];
foreach ($specs as $specName => $spec) {
if ($spec['category'] !== $category) {
continue;
}
if (isset($errors[$specName]) && $activeCategory === null) {
$activeCategory = $category;
}
$data[] = [
'name' => $specName,
'type' => $spec['type'],
Expand All @@ -103,6 +113,8 @@ public function indexAction(EventLogService $eventLogService, Request $request):
}
return $this->render('jury/config.html.twig', [
'options' => $allData,
'errors' => $errors ?? [],
'activeCategory' => $activeCategory ?? 'Scoring',
]);
}

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Entity/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Configuration
type: 'json',
options: ['comment' => 'Content of the configuration variable (JSON encoded)'])
]
private mixed $value;
private mixed $value = null;

public function getConfigid(): int
{
Expand Down
Loading

0 comments on commit a7571aa

Please sign in to comment.