Skip to content

Commit dd7b071

Browse files
authored
Merge pull request #60725 from nextcloud/backport/60654/stable33
[stable33] fix(config): add null coalescing fallback in getValueBool before strtolower
2 parents bbfa801 + 3df063f commit dd7b071

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

build/psalm-baseline.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,11 +3460,6 @@
34603460
<code><![CDATA[$CONFIG]]></code>
34613461
</UndefinedVariable>
34623462
</file>
3463-
<file src="lib/private/Config/UserConfig.php">
3464-
<RedundantCast>
3465-
<code><![CDATA[(string)$this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL)]]></code>
3466-
</RedundantCast>
3467-
</file>
34683463
<file src="lib/private/Console/Application.php">
34693464
<NoInterfaceProperties>
34703465
<code><![CDATA[$this->request->server]]></code>

lib/private/AppConfig.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,15 @@ public function getValueFloat(string $app, string $key, float $default = 0, bool
424424
* @see IAppConfig for explanation about lazy loading
425425
*/
426426
public function getValueBool(string $app, string $key, bool $default = false, bool $lazy = false): bool {
427-
$b = strtolower($this->getTypedValue($app, $key, $default ? 'true' : 'false', $lazy, self::VALUE_BOOL));
427+
// The explicit (string) cast and ?? null guard defend against a PHP OPcache bug where
428+
// values passed by reference across function boundaries can have their type corrupted
429+
// (e.g. bool returned as int, or null). Affects PHP 8.x with OPcache enabled; fixed
430+
// upstream in https://github.com/php/php-src/pull/21973. Keep until minimum PHP version
431+
// is bumped. Psalm sees the declared return type (string) and flags these as redundant.
432+
/** @psalm-suppress RedundantCondition, TypeDoesNotContainNull */
433+
$value = $this->getTypedValue($app, $key, $default ? 'true' : 'false', $lazy, self::VALUE_BOOL) ?? ($default ? 'true' : 'false');
434+
/** @psalm-suppress RedundantCast */
435+
$b = strtolower((string)$value);
428436
return in_array($b, ['1', 'true', 'yes', 'on']);
429437
}
430438

lib/private/Config/UserConfig.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,15 @@ public function getValueBool(
685685
bool $default = false,
686686
bool $lazy = false,
687687
): bool {
688-
// The explicit (string) cast guards against a PHP OPcache bug where values passed
689-
// by reference across function boundaries can have their type corrupted (e.g. bool
690-
// returned as int). Affects PHP 8.x with OPcache enabled; fixed upstream in
691-
// https://github.com/php/php-src/pull/21973. Keep until minimum PHP version is bumped.
692-
$b = strtolower((string)$this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL));
688+
// The explicit (string) cast and ?? null guard defend against a PHP OPcache bug where
689+
// values passed by reference across function boundaries can have their type corrupted
690+
// (e.g. bool returned as int, or null). Affects PHP 8.x with OPcache enabled; fixed
691+
// upstream in https://github.com/php/php-src/pull/21973. Keep until minimum PHP version
692+
// is bumped. Psalm sees the declared return type (string) and flags these as redundant.
693+
/** @psalm-suppress RedundantCondition, TypeDoesNotContainNull */
694+
$value = $this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL) ?? ($default ? 'true' : 'false');
695+
/** @psalm-suppress RedundantCast */
696+
$b = strtolower((string)$value);
693697
return in_array($b, ['1', 'true', 'yes', 'on']);
694698
}
695699

0 commit comments

Comments
 (0)