From 76e5b1af7c2bbb8b8c8b2cc36a60738d10f57d9f Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 9 Dec 2021 11:28:10 +0100 Subject: [PATCH] Check resource before closing in encryption wrapper In case of error there is no guarantee that $source or $target is set or is a resource when handling an error. Without this fix, there's a risk that fclose will fail and the actual exception will not be thrown, making it impossible to find out about the root cause. Signed-off-by: Vincent Petry --- lib/private/Files/Storage/Wrapper/Encryption.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index a52c87ec5a1ed..5ba989e0e84c3 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -756,8 +756,12 @@ private function copyBetweenStorage(Storage\IStorage $sourceStorage, $sourceInte fclose($source); fclose($target); } catch (\Exception $e) { - fclose($source); - fclose($target); + if (is_resource($source)) { + fclose($source); + } + if (is_resource($target)) { + fclose($target); + } throw $e; } if ($result) {