summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2010-10-28 11:58:56 +0100
committerRichard W.M. Jones <rjones@redhat.com>2010-10-28 15:16:14 +0100
commit2f52a40bed27e49972b957f1ef3276c422d5ef96 (patch)
treec8fb73643b27b17f70448c6e042843694586b9dc
parentf93b234401093c63e67f2ffc254f611eee4daf7c (diff)
downloadlibguestfs-2f52a40bed27e49972b957f1ef3276c422d5ef96.tar.gz
libguestfs-2f52a40bed27e49972b957f1ef3276c422d5ef96.tar.xz
libguestfs-2f52a40bed27e49972b957f1ef3276c422d5ef96.zip
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.
-rwxr-xr-xtools/virt-edit9
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/virt-edit b/tools/virt-edit
index 887ef4b6..78316fd0 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;
}