From: Richard W.M. Jones Date: Thu, 28 Oct 2010 10:58:56 +0000 (+0100) Subject: edit: Clean up tmp file handling in virt-edit. X-Git-Tag: 1.5.25~12 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=2f52a40bed27e49972b957f1ef3276c422d5ef96 edit: Clean up tmp file handling in virt-edit. This was probably not a security issue, but this change makes the code cleaner by not opening the tmp file twice. Also be more careful about error checking in close syscall. --- diff --git a/tools/virt-edit b/tools/virt-edit index 887ef4b..78316fd 100755 --- a/tools/virt-edit +++ b/tools/virt-edit @@ -198,10 +198,13 @@ my $root_dev = $roots[0]; my $os = $oses->{$root_dev}; mount_operating_system ($g, $os, 0); -my ($fh_not_used, $tempname) = tempfile (UNLINK => 1); +my ($fh, $tempname) = tempfile (UNLINK => 1); +my $fddev = "/dev/fd/" . fileno ($fh); # Allow this to fail in case eg. the file does not exist. -$g->download($filename, $tempname); +$g->download ($filename, $fddev); + +close $fh or die "close: $!"; my $do_upload = $tempname; @@ -232,7 +235,7 @@ if (!defined $expr) { die if $@; print $fh $_ or die "print: $!"; } - close $fh; + close $fh or die "close: $!"; $do_upload = $tempout; }