|
|
@@ -145,17 +145,43 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // problem.conf can also arrive inside a zip that the problem's controller
|
|
|
+ // uploads, so *every* value in it is attacker-controlled: the field checks in
|
|
|
+ // problem_data_manage.php are not a security boundary, because the zip upload
|
|
|
+ // path never goes through them. input_pre / input_suf / output_pre /
|
|
|
+ // output_suf used to be concatenated straight into a filesystem path, so
|
|
|
+ //
|
|
|
+ // input_pre x/../../../../../opt/uoj/web/shell.
|
|
|
+ // input_suf php
|
|
|
+ //
|
|
|
+ // made dataAddExtraTest() move an uploaded hack input to
|
|
|
+ // /opt/uoj/web/shell.1.php -- an arbitrary-content arbitrary-path write into
|
|
|
+ // the document root, i.e. remote code execution as the web user.
|
|
|
+ //
|
|
|
+ // Only a bare filename component is ever legitimate here. Anything else
|
|
|
+ // (separators, "..", absolute paths, ...) falls back to the default instead of
|
|
|
+ // escaping the problem's own data directory. Same idea as the whitelist that
|
|
|
+ // already guards use_builtin_checker in uoj-data-lib.php.
|
|
|
+ function getUOJConfFileNamePart($conf, $key, $default_val) {
|
|
|
+ $val = getUOJConfVal($conf, $key, $default_val);
|
|
|
+ if (!is_string($val) || !preg_match('/^[A-Za-z0-9_.-]*$/', $val) || strpos($val, '..') !== false) {
|
|
|
+ error_log("uoj: ignoring unsafe problem.conf value for '$key'");
|
|
|
+ return $default_val;
|
|
|
+ }
|
|
|
+ return $val;
|
|
|
+ }
|
|
|
+
|
|
|
function getUOJProblemInputFileName($problem_conf, $num) {
|
|
|
- return getUOJConfVal($problem_conf, 'input_pre', 'input') . $num . '.' . getUOJConfVal($problem_conf, 'input_suf', 'txt');
|
|
|
+ return getUOJConfFileNamePart($problem_conf, 'input_pre', 'input') . $num . '.' . getUOJConfFileNamePart($problem_conf, 'input_suf', 'txt');
|
|
|
}
|
|
|
function getUOJProblemOutputFileName($problem_conf, $num) {
|
|
|
- return getUOJConfVal($problem_conf, 'output_pre', 'output') . $num . '.' . getUOJConfVal($problem_conf, 'output_suf', 'txt');
|
|
|
+ return getUOJConfFileNamePart($problem_conf, 'output_pre', 'output') . $num . '.' . getUOJConfFileNamePart($problem_conf, 'output_suf', 'txt');
|
|
|
}
|
|
|
function getUOJProblemExtraInputFileName($problem_conf, $num) {
|
|
|
- return 'ex_' . getUOJConfVal($problem_conf, 'input_pre', 'input') . $num . '.' . getUOJConfVal($problem_conf, 'input_suf', 'txt');
|
|
|
+ return 'ex_' . getUOJConfFileNamePart($problem_conf, 'input_pre', 'input') . $num . '.' . getUOJConfFileNamePart($problem_conf, 'input_suf', 'txt');
|
|
|
}
|
|
|
function getUOJProblemExtraOutputFileName($problem_conf, $num) {
|
|
|
- return 'ex_' . getUOJConfVal($problem_conf, 'output_pre', 'output') . $num . '.' . getUOJConfVal($problem_conf, 'output_suf', 'txt');
|
|
|
+ return 'ex_' . getUOJConfFileNamePart($problem_conf, 'output_pre', 'output') . $num . '.' . getUOJConfFileNamePart($problem_conf, 'output_suf', 'txt');
|
|
|
}
|
|
|
|
|
|
function rejudgeProblem($problem) {
|