]> source.dussan.org Git - nextcloud-server.git/commitdiff
Check resource before closing in encryption wrapper 30182/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:10:44 +0000 (00:10 +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 ef5697cdd243556aa985262b984e5306d9b6fdb9..7aa092ba61f8ce265b95dd5445de3697d854c240 100644 (file)
@@ -756,8 +756,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) {