Skip to content

Commit

Permalink
Explicitly cast to string when string is expected
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Aug 25, 2023
1 parent 72068f9 commit 8c04896
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function createServer(
$config = $this->config;

$server->on('beforeMethod:PROPFIND', function (Request $request) use ($config) {
$depthHeader = strtolower($request->getHeader('depth'));
$depthHeader = strtolower((string)$request->getHeader('depth'));

if ($depthHeader === 'infinity' && !$config->getSystemValue('dav.propfind.depth_infinity', false)) {
throw new PreconditionFailed('Depth infinity not supported');
Expand Down
6 changes: 6 additions & 0 deletions changelog/unreleased/40944
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: cast to string when string is expected

The code now explicitly casts variables to string when they can be null and
are passed to functions that expect a string.

https://github.com/owncloud/core/pull/40944
2 changes: 1 addition & 1 deletion lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ protected function decodeContent() {
$params = [];

// 'application/json' must be decoded manually.
if (\strpos($this->getHeader('Content-Type'), 'application/json') !== false) {
if (\strpos($this->getHeader('Content-Type') ?? '', 'application/json') !== false) {
$params = \json_decode(\file_get_contents($this->inputStream), true);
if (\is_array($params) && \count($params) > 0) {
$this->items['params'] = $params;
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Security/Crypto.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function decrypt($authenticatedCiphertext, $password = '') {
$password = $this->config->getSystemValue('secret');
}

$parts = \explode('|', $authenticatedCiphertext);
$parts = \explode('|', (string)$authenticatedCiphertext);

// v2 uses stronger binary random iv
if (\sizeof($parts) === 4 && $parts[0] === 'v2') {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Setup/AbstractDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function initialize($config) {
$dbUser = $config['dbuser'];
$dbPass = $config['dbpass'];
$dbName = $config['dbname'];
$dbConnectionString = $config['dbconnectionstring'];
$dbConnectionString = $config['dbconnectionstring'] ?? '';
$dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
$dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';

Expand Down
2 changes: 1 addition & 1 deletion lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ public function setNewRememberMeTokenForLoggedInUser() {
public function clearRememberMeTokensForLoggedInUser($targetToken) {
$user = $this->getUser();
$uid = $user->getUID();
$hashedToken = \hash('snefru', $targetToken);
$hashedToken = \hash('snefru', (string)$targetToken);

$keys = $this->config->getUserKeys($uid, 'login_token');
foreach ($keys as $key) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public static function is_function_enabled($function_name) {
if (\in_array($function_name, $disabled)) {
return false;
}
$disabled = \explode(',', $ini->get('suhosin.executor.func.blacklist'));
$disabled = \explode(',', (string)$ini->get('suhosin.executor.func.blacklist'));
$disabled = \array_map('trim', $disabled);
if (\in_array($function_name, $disabled)) {
return false;
Expand Down

0 comments on commit 8c04896

Please sign in to comment.