Skip to content

Commit 76e5b1a

Browse files
PVince81backportbot[bot]
authored andcommitted
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 <vincent@nextcloud.com>
1 parent 0774a94 commit 76e5b1a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/private/Files/Storage/Wrapper/Encryption.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,12 @@ private function copyBetweenStorage(Storage\IStorage $sourceStorage, $sourceInte
756756
fclose($source);
757757
fclose($target);
758758
} catch (\Exception $e) {
759-
fclose($source);
760-
fclose($target);
759+
if (is_resource($source)) {
760+
fclose($source);
761+
}
762+
if (is_resource($target)) {
763+
fclose($target);
764+
}
761765
throw $e;
762766
}
763767
if ($result) {

0 commit comments

Comments
 (0)