From: Charles McGarvey Date: Tue, 19 Apr 2022 15:25:18 +0000 (-0600) Subject: Be sure to not lose $@ when loading KDBX files X-Git-Tag: v0.800~25 X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-File-KDBX;a=commitdiff_plain;h=cfe6ddf632ec8f9ce9569fbf4c7e759160ba3419 Be sure to not lose $@ when loading KDBX files --- 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