From: Charles McGarvey Date: Sun, 1 May 2022 20:59:26 +0000 (-0600) Subject: Save stream offset in safe to fix locked peeking X-Git-Tag: v0.901~3 X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=ad2fb90df76a3599c61081f787f387b1a84a89ca;p=chaz%2Fp5-File-KDBX Save stream offset in safe to fix locked peeking This fixes a bug where peeking at protected strings and binaries does not work without unlocking the database at least once. --- diff --git a/Changes b/Changes index c0f24ec..1f54ece 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ Revision history for File-KDBX. {{$NEXT}} + * Fix a bug where peeking at memory-protected strings and binaries does not + work without unlocking the database at least once. + 0.900 2022-05-01 12:55:59-0600 * Removed the min_version methods from dumper and loader because it was diff --git a/lib/File/KDBX/Safe.pm b/lib/File/KDBX/Safe.pm index 8e307c2..e8b5fd9 100644 --- a/lib/File/KDBX/Safe.pm +++ b/lib/File/KDBX/Safe.pm @@ -151,7 +151,7 @@ sub add_protected { @strings or throw 'Must provide strings to lock'; for my $string (@strings) { - my $item = {str => $string}; + my $item = {str => $string, off => $self->{counter}}; $item->{filter} = $filter if defined $filter; if (is_scalarref($string)) { next if !defined $$string; diff --git a/t/kdbx3.t b/t/kdbx3.t index 5fe53f7..fac6101 100644 --- a/t/kdbx3.t +++ b/t/kdbx3.t @@ -105,10 +105,12 @@ subtest 'Verify ProtectedStrings' => sub { is $kdbx->meta->{database_name}, 'Protected Strings Test', 'Extract database name from meta'; - $kdbx->unlock; - my $entry = $kdbx->entries->next; is $entry->title, 'Sample Entry', 'Get entry title'; + + is $entry->string_peek('Password'), 'ProtectedPassword', 'Peek at password from entry'; + is $entry->string_peek('TestProtected'), 'ABC', 'Peek at protected string from entry'; + $kdbx->unlock; is $entry->username, 'Protected User Name', 'Get protected username from entry'; is $entry->password, 'ProtectedPassword', 'Get protected password from entry'; is $entry->string_value('TestProtected'), 'ABC', 'Get ABC string from entry';