From 15fe8e62d37bc87114c59d385bed7ceefb72886b Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 12 Aug 2016 13:55:09 +0200 Subject: fileutl: empty file support: Avoid fstat() on -1 fd and check result When checking if a file is empty, we forget to check that fstat() actually worked. --- apt-pkg/contrib/fileutl.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'apt-pkg/contrib/fileutl.cc') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index a9d51a6bf..fd13b45dc 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1908,11 +1908,12 @@ public: " but was forced to ignore it in favor of an external binary – which isn't installed.", compressor.Name.c_str()); bool const Comp = (Mode & FileFd::WriteOnly) == FileFd::WriteOnly; - if (Comp == false) + if (Comp == false && filefd->iFd != -1) { // Handle 'decompression' of empty files struct stat Buf; - fstat(filefd->iFd, &Buf); + if (fstat(filefd->iFd, &Buf) != 0) + return filefd->FileFdErrno("fstat", "Could not stat fd %d for file %s", filefd->iFd, filefd->FileName.c_str()); if (Buf.st_size == 0 && S_ISFIFO(Buf.st_mode) == false) return true; -- cgit v1.2.3