[Libguestfs] [PATCH 2/2] SSH: Don't mix buffered reads with sysread

Matthew Booth mbooth at redhat.com
Thu Apr 29 10:47:49 UTC 2010


SSH transfer contained a race due to use of buffered IO to read the initial
size, followed by sysread() to read the data. If data was available for reading
at the time the size was read, some of it would be consumed and buffered. It
would subsequently not be available to sysread(), meaning it wasn't copied.

Fix by using buffered IO consistently.
---
 lib/Sys/VirtV2V/Transfer/SSH.pm |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/Sys/VirtV2V/Transfer/SSH.pm b/lib/Sys/VirtV2V/Transfer/SSH.pm
index ac5a384..0868b37 100644
--- a/lib/Sys/VirtV2V/Transfer/SSH.pm
+++ b/lib/Sys/VirtV2V/Transfer/SSH.pm
@@ -86,7 +86,7 @@ sub transfer
     for (;;) {
         my $buffer;
         # Transfer in 8k chunks
-        my $in = sysread($fh, $buffer, 8 * 1024);
+        my $in = read($fh, $buffer, 8 * 1024);
         die(user_message(__x("Error reading data from {path}: {error}",
                              path => $path,
                              error => $!))) if (!defined($in));
-- 
1.6.6.1




More information about the Libguestfs mailing list