From cfe6ddf632ec8f9ce9569fbf4c7e759160ba3419 Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Tue, 19 Apr 2022 09:25:18 -0600 Subject: [PATCH] Be sure to not lose $@ when loading KDBX files --- lib/File/KDBX/Loader.pm | 12 +++++++++++- lib/File/KDBX/Loader/V3.pm | 1 + lib/File/KDBX/Safe.pm | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/File/KDBX/Loader.pm b/lib/File/KDBX/Loader.pm index 844f038..9f51321 100644 --- a/lib/File/KDBX/Loader.pm +++ b/lib/File/KDBX/Loader.pm @@ -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 { diff --git a/lib/File/KDBX/Loader/V3.pm b/lib/File/KDBX/Loader/V3.pm index f7f9516..77ad479 100644 --- a/lib/File/KDBX/Loader/V3.pm +++ b/lib/File/KDBX/Loader/V3.pm @@ -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); diff --git a/lib/File/KDBX/Safe.pm b/lib/File/KDBX/Safe.pm index 0e445c6..8e307c2 100644 --- a/lib/File/KDBX/Safe.pm +++ b/lib/File/KDBX/Safe.pm @@ -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 -- 2.45.2