]> git.saurik.com Git - apt.git/commitdiff
CopyFile: avoid failing on EOF on some systems
authorPino Toscano <pino@debian.org>
Sat, 19 Dec 2015 11:06:53 +0000 (12:06 +0100)
committerJulian Andres Klode <jak@debian.org>
Sat, 19 Dec 2015 11:52:45 +0000 (12:52 +0100)
On EOF, ToRead will be 0, which might trigger on some systems (e.g.
on the Hurd) an error due to the invalid byte count passed to write().
The whole loop already checks for ToRead != 0, so perform the writing
step only when there was actual data read.

Closes: #808381
apt-pkg/contrib/fileutl.cc

index 86ca82cff2c4b17c02ea600374898dd1bc52dc8c..1ffa407bc9cd017259a1366135bcffb1afffa7d3 100644 (file)
@@ -165,7 +165,7 @@ bool CopyFile(FileFd &From,FileFd &To)
    unsigned long long ToRead = 0;
    do {
       if (From.Read(Buf.get(),BufSize, &ToRead) == false ||
-         To.Write(Buf.get(),ToRead) == false)
+         (ToRead > 0 && To.Write(Buf.get(),ToRead) == false))
         return false;
    } while (ToRead != 0);