Pārlūkot izejas kodu

CopyFile: avoid failing on EOF on some systems

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
Pino Toscano 10 gadi atpakaļ
vecāks
revīzija
c0b271edc2
1 mainītis faili ar 1 papildinājumiem un 1 dzēšanām
  1. 1 1
      apt-pkg/contrib/fileutl.cc

+ 1 - 1
apt-pkg/contrib/fileutl.cc

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