From 00eeb686bfcd625c8cdf870843b7d1f4d553c185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 15 Feb 2017 09:23:02 +0100 Subject: [PATCH] MDL-57896 admin: Prevent cfg.php from trying to change hard-set value Credit goes to Andrew Nicols for spotting and suggesting this check. --- admin/cli/cfg.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/admin/cli/cfg.php b/admin/cli/cfg.php index 01b2be955bb..463a0ab2ea1 100644 --- a/admin/cli/cfg.php +++ b/admin/cli/cfg.php @@ -61,8 +61,9 @@ In the read mode, the script exits with success status 0 if the requested value is found. If the requested variable is not set, the script exits with status 3. When listing all variables of the component, the exit status is always 0 even if no variables for the given component are found. When setting/unsetting a -value, the exit status is 0. In case of unexpected error, the script exits with -error status 1. +value, the exit status is 0. When attempting to set/unset a value that has +already been hard-set in config.php, the script exits with error status 4. In +case of unexpected error, the script exits with error status 1. Examples: @@ -117,6 +118,12 @@ if ($options['unset'] || $options['set'] !== null) { if (empty($options['name'])) { cli_error('Missing configuration variable name', 2); } + + // Check that the variable is not hard-set in the main config.php already. + if (array_key_exists($options['name'], $CFG->config_php_settings)) { + cli_error('The configuration variable is hard-set in the config.php, unable to change.', 4); + } + set_config($options['name'], $options['set'], $options['component']); exit(0); }