aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Config.php
diff options
context:
space:
mode:
authorVarun Patil <varunpatil@ucla.edu>2024-03-15 10:24:17 -0700
committerEduardo Morales <emoral435@gmail.com>2024-04-03 08:19:20 -0500
commitd41918f4ab92583551c8d58339c6a3df65a76408 (patch)
treecb4401e3df4b72ad2402bb257bc4863f5afa22b7 /lib/private/Config.php
parente655e52ca0a60d5f45cd5d92054231b94ef012b6 (diff)
downloadnextcloud-server-d41918f4ab92583551c8d58339c6a3df65a76408.tar.gz
nextcloud-server-d41918f4ab92583551c8d58339c6a3df65a76408.zip
fix(config): correctness issues in reading
Signed-off-by: Varun Patil <varunpatil@ucla.edu>
Diffstat (limited to 'lib/private/Config.php')
-rw-r--r--lib/private/Config.php39
1 files changed, 26 insertions, 13 deletions
diff --git a/lib/private/Config.php b/lib/private/Config.php
index 3ea822101df..803ce859de4 100644
--- a/lib/private/Config.php
+++ b/lib/private/Config.php
@@ -215,13 +215,24 @@ class Config {
// Include file and merge config
foreach ($configFiles as $file) {
- $fileExistsAndIsReadable = file_exists($file) && is_readable($file);
- $filePointer = $fileExistsAndIsReadable ? fopen($file, 'r') : false;
- if ($file === $this->configFilePath &&
- $filePointer === false) {
- // Opening the main config might not be possible, e.g. if the wrong
- // permissions are set (likely on a new installation)
- continue;
+ unset($CONFIG);
+
+ // Invalidate opcache (only if the timestamp changed)
+ if (function_exists('opcache_invalidate')) {
+ opcache_invalidate($file, false);
+ }
+
+ $filePointer = @fopen($file, 'r');
+ if ($filePointer === false) {
+ // e.g. wrong permissions are set
+ if ($file === $this->configFilePath) {
+ // opening the main config file might not be possible
+ // (likely on a new installation)
+ continue;
+ }
+
+ http_response_code(500);
+ die(sprintf('FATAL: Could not open the config file %s', $file));
}
// Try to acquire a file lock
@@ -229,8 +240,14 @@ class Config {
throw new \Exception(sprintf('Could not acquire a shared lock on the config file %s', $file));
}
- unset($CONFIG);
- include $file;
+ try {
+ include $file;
+ } finally {
+ // Close the file pointer and release the lock
+ flock($filePointer, LOCK_UN);
+ fclose($filePointer);
+ }
+
if (!defined('PHPUNIT_RUN') && headers_sent()) {
// syntax issues in the config file like leading spaces causing PHP to send output
$errorMessage = sprintf('Config file has leading content, please remove everything before "<?php" in %s', basename($file));
@@ -242,10 +259,6 @@ class Config {
if (isset($CONFIG) && is_array($CONFIG)) {
$this->cache = array_merge($this->cache, $CONFIG);
}
-
- // Close the file pointer and release the lock
- flock($filePointer, LOCK_UN);
- fclose($filePointer);
}
$this->envCache = getenv();