]> source.dussan.org Git - nextcloud-server.git/commitdiff
Check resource before closing in encryption wrapper 30180/head
authorVincent Petry <vincent@nextcloud.com>
Thu, 9 Dec 2021 10:28:10 +0000 (11:28 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Fri, 10 Dec 2021 00:03:08 +0000 (00:03 +0000)
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 <vincent@nextcloud.com>
lib/private/Files/Storage/Wrapper/Encryption.php

index 308952c2a31b62b6310b58404d7b75e8bf79dfce..3ee715ae3d32a71f48cfe832bb43a453ce49f65d 100644 (file)
@@ -784,8 +784,12 @@ class Encryption extends Wrapper {
                                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) {