Skip to content

Commit b75ce7e

Browse files
committed
fix: hardening for opcache.enable_file_override
If the PHP instance has aggressive caching enabled, with `opcache.enable_file_override` and sufficiently long or disabled `opcache.validate_timestamps`, `file_exists($versionFileName)` can retrun true after the file was removed from disk. `require_once $versionFileName;` however requires the file to exist on disk, even if it has an OPcache entry. With this commit, the cache entry is invalidated before `file_exists($versionFileName)` is called, to harden the updater for instances with `opcache.enable_file_override`. Signed-off-by: MichaIng <micha@dietpi.com>
1 parent 7d8b694 commit b75ce7e

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

index.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public function __construct(
8282
}
8383

8484
$versionFileName = $this->nextcloudDir . '/version.php';
85+
// Invalidate version.php OPcache entry to assure file_exists() returns
86+
// false after files were removed while opcache.enable_file_override is set.
87+
if (function_exists('opcache_invalidate')) {
88+
opcache_invalidate($versionFileName, true);
89+
}
8590
if (!file_exists($versionFileName)) {
8691
// fallback to version in config.php
8792
$version = $this->getConfigOptionString('version');

lib/Updater.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public function __construct(
6666
}
6767

6868
$versionFileName = $this->nextcloudDir . '/version.php';
69+
// Invalidate version.php OPcache entry to assure file_exists() returns
70+
// false after files were removed while opcache.enable_file_override is set.
71+
if (function_exists('opcache_invalidate')) {
72+
opcache_invalidate($versionFileName, true);
73+
}
6974
if (!file_exists($versionFileName)) {
7075
// fallback to version in config.php
7176
$version = $this->getConfigOptionString('version');

updater.phar

251 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)