From 29c30a361b06e9451a437aa1d8a3b7de80ebd849 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 9 Nov 2022 11:45:15 +0000 Subject: [PATCH 1/4] Fix null warnings - Fixed Avatars isset operator - Added isset operator to openSSL data in files - dns_get_record does not throw errors, instead it logs a warning and returns false. Altered code accordingly. PHP Bug Report: https://bugs.php.net/bug.php?id=73149 - --- app/controllers/api/avatars.php | 4 ++-- app/controllers/api/storage.php | 14 +++++++------- src/Appwrite/Network/Validator/CNAME.php | 4 ++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index b7aef1505b..25c9fe8659 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -242,8 +242,8 @@ App::get('/v1/avatars/favicon') case 'jpeg': $size = \explode('x', \strtolower($sizes)); - $sizeWidth = (int) $size[0] ?? 0; - $sizeHeight = (int) $size[1] ?? 0; + $sizeWidth = (int) ($size[0] ?? 0); + $sizeHeight = (int) ($size[1] ?? 0); if (($sizeWidth * $sizeHeight) >= $space) { $space = $sizeWidth * $sizeHeight; diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 530f174cd0..04ff10ca61 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -565,10 +565,10 @@ App::post('/v1/storage/buckets/:bucketId/files') 'comment' => '', 'chunksTotal' => $chunks, 'chunksUploaded' => $chunksUploaded, - 'openSSLVersion' => $openSSLVersion, - 'openSSLCipher' => $openSSLCipher, - 'openSSLTag' => $openSSLTag, - 'openSSLIV' => $openSSLIV, + 'openSSLVersion' => $openSSLVersion ?? null, + 'openSSLCipher' => $openSSLCipher ?? null, + 'openSSLTag' => $openSSLTag ?? null, + 'openSSLIV' => $openSSLIV ?? null, 'search' => implode(' ', [$fileId, $fileName]), 'metadata' => $metadata, ]); @@ -581,9 +581,9 @@ App::post('/v1/storage/buckets/:bucketId/files') ->setAttribute('mimeType', $mimeType) ->setAttribute('sizeActual', $sizeActual) ->setAttribute('algorithm', $algorithm) - ->setAttribute('openSSLVersion', $openSSLVersion) - ->setAttribute('openSSLCipher', $openSSLCipher) - ->setAttribute('openSSLTag', $openSSLTag) + ->setAttribute('openSSLVersion', $openSSLVersion ?? null) + ->setAttribute('openSSLCipher', $openSSLCipher ?? null) + ->setAttribute('openSSLTag', $openSSLTag ?? null) ->setAttribute('openSSLIV', $openSSLIV) ->setAttribute('metadata', $metadata) ->setAttribute('chunksUploaded', $chunksUploaded); diff --git a/src/Appwrite/Network/Validator/CNAME.php b/src/Appwrite/Network/Validator/CNAME.php index 93a302b962..678a57cecd 100644 --- a/src/Appwrite/Network/Validator/CNAME.php +++ b/src/Appwrite/Network/Validator/CNAME.php @@ -46,6 +46,10 @@ class CNAME extends Validator return false; } + if (!$records) { + return false; + } + foreach ($records as $record) { if (isset($record['target']) && $record['target'] === $this->target) { return true; From a0ab93432845fd6e807bad4921d2c6063c574996 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 9 Nov 2022 13:23:14 +0000 Subject: [PATCH 2/4] Fix another null warning --- app/controllers/api/storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 04ff10ca61..837bb9e541 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -584,7 +584,7 @@ App::post('/v1/storage/buckets/:bucketId/files') ->setAttribute('openSSLVersion', $openSSLVersion ?? null) ->setAttribute('openSSLCipher', $openSSLCipher ?? null) ->setAttribute('openSSLTag', $openSSLTag ?? null) - ->setAttribute('openSSLIV', $openSSLIV) + ->setAttribute('openSSLIV', $openSSLIV ?? null) ->setAttribute('metadata', $metadata) ->setAttribute('chunksUploaded', $chunksUploaded); From bc915483ff96e74e9c06257e02ab76e9bb0add89 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 9 Nov 2022 13:52:46 +0000 Subject: [PATCH 3/4] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 2c649ab5f0..0230b0f840 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ ## Bugs - Fix license detection for Flutter and Dart SDKs [#4435](https://github.com/appwrite/appwrite/pull/4435) - Fix missing realtime event for create function deployment [#4574](https://github.com/appwrite/appwrite/pull/4574) +- Fix a few null safety warnings [#4654](https://github.com/appwrite/appwrite/pull/4654) # Version 1.0.3 ## Bugs From a19e668d790392fce616528931801ec509da7b3d Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 14 Nov 2022 13:11:43 +0000 Subject: [PATCH 4/4] Update storage.php --- app/controllers/api/storage.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 837bb9e541..690c0050ad 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -542,6 +542,11 @@ App::post('/v1/storage/buckets/:bucketId/files') $sizeActual = $deviceFiles->getFileSize($path); $fileHash = $deviceFiles->getFileHash($path); + $openSSLVersion = null; + $openSSLCipher = null; + $openSSLTag = null; + $openSSLIV = null; + if ($bucket->getAttribute('encryption', true) && $fileSize <= APP_STORAGE_READ_BUFFER) { $openSSLVersion = '1'; $openSSLCipher = OpenSSL::CIPHER_AES_128_GCM; @@ -565,10 +570,10 @@ App::post('/v1/storage/buckets/:bucketId/files') 'comment' => '', 'chunksTotal' => $chunks, 'chunksUploaded' => $chunksUploaded, - 'openSSLVersion' => $openSSLVersion ?? null, - 'openSSLCipher' => $openSSLCipher ?? null, - 'openSSLTag' => $openSSLTag ?? null, - 'openSSLIV' => $openSSLIV ?? null, + 'openSSLVersion' => $openSSLVersion, + 'openSSLCipher' => $openSSLCipher, + 'openSSLTag' => $openSSLTag, + 'openSSLIV' => $openSSLIV, 'search' => implode(' ', [$fileId, $fileName]), 'metadata' => $metadata, ]); @@ -581,10 +586,10 @@ App::post('/v1/storage/buckets/:bucketId/files') ->setAttribute('mimeType', $mimeType) ->setAttribute('sizeActual', $sizeActual) ->setAttribute('algorithm', $algorithm) - ->setAttribute('openSSLVersion', $openSSLVersion ?? null) - ->setAttribute('openSSLCipher', $openSSLCipher ?? null) - ->setAttribute('openSSLTag', $openSSLTag ?? null) - ->setAttribute('openSSLIV', $openSSLIV ?? null) + ->setAttribute('openSSLVersion', $openSSLVersion) + ->setAttribute('openSSLCipher', $openSSLCipher) + ->setAttribute('openSSLTag', $openSSLTag) + ->setAttribute('openSSLIV', $openSSLIV) ->setAttribute('metadata', $metadata) ->setAttribute('chunksUploaded', $chunksUploaded);