]> Dogcows Code - chaz/p5-File-KDBX/commitdiff
Save stream offset in safe to fix locked peeking
authorCharles McGarvey <ccm@cpan.org>
Sun, 1 May 2022 20:59:26 +0000 (14:59 -0600)
committerCharles McGarvey <ccm@cpan.org>
Sun, 1 May 2022 21:11:15 +0000 (15:11 -0600)
This fixes a bug where peeking at protected strings and binaries does
not work without unlocking the database at least once.

Changes
lib/File/KDBX/Safe.pm
t/kdbx3.t

diff --git a/Changes b/Changes
index c0f24ec2b21fac4025f004b07c08c8abd672e564..1f54ece58d42c54182d57787da9be101214c9dc3 100644 (file)
--- 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
index 8e307c25743f6753db2f9766cdd755047990c69e..e8b5fd94963b8ee3835da4e7fb6d2a9a4acdc280 100644 (file)
@@ -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;
index 5fe53f7b820026fdc60ba1b9cf538bc49f0d6ac4..fac610197039aea31a76d6afc3a6cb6148854d20 100644 (file)
--- 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';
This page took 0.030562 seconds and 4 git commands to generate.