]> Dogcows Code - chaz/p5-File-KDBX/commitdiff
Be sure to not lose $@ when loading KDBX files
authorCharles McGarvey <ccm@cpan.org>
Tue, 19 Apr 2022 15:25:18 +0000 (09:25 -0600)
committerCharles McGarvey <ccm@cpan.org>
Sun, 1 May 2022 00:29:00 +0000 (18:29 -0600)
lib/File/KDBX/Loader.pm
lib/File/KDBX/Loader/V3.pm
lib/File/KDBX/Safe.pm

index 844f038098e8426518b1f77f5d2dd42fef4c2164..9f513218949255a234b2438d4c4a6e5276708246 100644 (file)
@@ -303,7 +303,17 @@ sub _read {
 
     my $headers = $self->_read_headers($fh);
 
-    $self->_read_body($fh, $key, "$magic$headers");
+    eval {
+        $self->_read_body($fh, $key, "$magic$headers");
+    };
+    if (my $err = $@) {
+        throw "Failed to load KDBX file: $err",
+            error               => $err,
+            compression_error   => $IO::Uncompress::Gunzip::GunzipError,
+            crypt_error         => $File::KDBX::IO::Crypt::ERROR,
+            hash_error          => $File::KDBX::IO::HashBLock::ERROR,
+            hmac_error          => $File::KDBX::IO::HmacBLock::ERROR;
+    }
 }
 
 sub _read_headers {
index f7f951649169e92d99a9a3d6103ac3bbe89a6112..77ad479635abea9c3ea2ea56764f6161619bfb56 100644 (file)
@@ -152,6 +152,7 @@ sub _read_body {
     }
 
     $self->_read_inner_body($fh);
+    close($fh);
 
     if (my $header_hash = $kdbx->meta->{header_hash}) {
         my $got_header_hash = digest_data('SHA256', $header_data);
index 0e445c619154f95692be39b24062fbc150c8a500..8e307c25743f6753db2f9766cdd755047990c69e 100644 (file)
@@ -48,7 +48,7 @@ sub new {
     return $self;
 }
 
-sub DESTROY { !in_global_destruction and $_[0]->unlock }
+sub DESTROY { local ($., $@, $!, $^E, $?); !in_global_destruction and $_[0]->unlock }
 
 =method clear
 
This page took 0.027386 seconds and 4 git commands to generate.