From dc5038d15b222219bb3d2d852848107cec4453d7 Mon Sep 17 00:00:00 2001 From: "git@daemon.de" Date: Tue, 24 Mar 2015 11:22:54 +0100 Subject: [PATCH] applied patch by ddick --- CHANGELOG | 4 +++- README | 2 +- lib/Crypt/PWSafe3.pm | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d29ae21..4a2e89c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ -NEXT: +1.19: + applied patch by David Dick, which adds some more precautions + of i/o error handling and flushing. 1.17: added license to META diff --git a/README b/README index 8c7ddaa..c613568 100644 --- a/README +++ b/README @@ -52,5 +52,5 @@ AUTHOR VERSION - 1.17 + 1.19 diff --git a/lib/Crypt/PWSafe3.pm b/lib/Crypt/PWSafe3.pm index ff607c2..98d1f00 100644 --- a/lib/Crypt/PWSafe3.pm +++ b/lib/Crypt/PWSafe3.pm @@ -11,6 +11,8 @@ package Crypt::PWSafe3; use strict; +use Config; + use Carp::Heavy; use Carp; @@ -28,7 +30,7 @@ use Data::Dumper; use Exporter (); use vars qw(@ISA @EXPORT); -$Crypt::PWSafe3::VERSION = '1.18'; +$Crypt::PWSafe3::VERSION = '1.19'; use Crypt::PWSafe3::Field; use Crypt::PWSafe3::HeaderField; @@ -211,7 +213,8 @@ sub read { # read and decrypt an existing vault file my($this) = @_; - my $fd = FileHandle->new($this->file, 'r'); + my $file = $this->file(); + my $fd = FileHandle->new($file, 'r') or croak "Could not open $file for reading: $!"; $fd->binmode(); $this->{fd} = $fd; @@ -301,7 +304,7 @@ sub read { croak "File integrity check failed, invalid HMAC"; } - $this->{fd}->close(); + $this->{fd}->close() or croak "Could not close $file: $!"; } sub untaint { @@ -416,7 +419,10 @@ sub save { $this->hmac( $this->{hmacer}->digest() ); $this->writebytes($this->hmac); - $this->{fd}->close(); + if ($Config{d_fsync}) { + $this->{fd}->sync() or croak "Could not fsync: $!"; + } + $this->{fd}->close() or croak "Could not close tmpfile: $!"; # now try to read it in again to check if it # is valid what we created @@ -429,7 +435,7 @@ sub save { } else { # well, seems to be ok :) - move($tmpfile, $file); + move($tmpfile, $file) or croak "Could not move $tmpfile to $file: $!"; } } @@ -973,7 +979,7 @@ License 2.0, see: L =head1 VERSION -Crypt::PWSafe3 Version 1.17. +Crypt::PWSafe3 Version 1.19. =cut