From 731f5516a26610aed2d8bdaa988fa8c805f0b5d2 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 26 Mar 2015 09:41:54 +0100 Subject: Croak when mktemp, unlink or move fails. --- cli/icevault | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'cli/icevault') diff --git a/cli/icevault b/cli/icevault index e0c2757..ef186d0 100755 --- a/cli/icevault +++ b/cli/icevault @@ -379,7 +379,7 @@ sub saveIdentityFile($$) { # don't encrypt directly into the destination file so we don't # end up with a messed up file if something goes wrong - my $outfh = File::Temp->new(SUFFIX => '.gpg', UNLINK => 0, TMPDIR => 1); + my $outfh = File::Temp->new(SUFFIX => '.gpg', UNLINK => 0, TMPDIR => 1) or die; my $pid = IPC::Open2::open2( ">&".$outfh->fileno , (ref $form ? my $infh : "<&".fileno($NULL)) , $CONFIG{gpg}, qw/-o - --no-encrypt-to --recipient/, $CONFIG{keyid} @@ -398,10 +398,10 @@ sub saveIdentityFile($$) { my $parent_dir = $filename =~ s/\/[^\/]+$//r; File::Path::make_path($parent_dir) unless -d $parent_dir; # create parent directories recursively - unless (File::Copy::move($outfh->filename, $filename)){ + unless (File::Copy::move($outfh->filename, $filename)) { my $r = $!; - unlink $outfh->filename; - error "Can't move C<%s>: %s", $outfh->filename, $r; + unlink $outfh->filename or error "Can't unlink C<%s>: %s", $outfh->filename, $!; + error "Can't move C<%s> to C<%s>: %s", $outfh->filename, $filename, $r; } # TODO: git add $filename; git commit @@ -838,14 +838,13 @@ elsif ($command eq 'edit') { my $id = shift; my $filename = getIdentityFile $id; error "No such identity C<%s>", $id unless -f $filename; - require 'File/Copy.pm'; require 'File/Temp.pm'; error "C<%s> is not set", '$EDITOR' unless defined $ENV{EDITOR}; $ENV{EDITOR} =~ /\A(\p{Print}+)\z/ or error "Insecure C<%s>", "\$EDITOR"; my $EDITOR = $1; # untaint $EDITOR - my $fh = File::Temp->new(SUFFIX => '.yaml', UNLINK => 0, TMPDIR => 1); + my $fh = File::Temp->new(SUFFIX => '.yaml', UNLINK => 0, TMPDIR => 1) or die; END { unlink $fh->filename if defined $fh; } # never leave cleartext lying around loadIdentityFile $filename, $fh; -- cgit v1.2.3