summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/fileutl.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2016-08-12 13:55:09 +0200
committerJulian Andres Klode <jak@debian.org>2016-10-05 21:53:37 +0200
commit984a637a21acbbecc7ebec3f6eada09a221f068b (patch)
tree565d4ce62eb909d44e7a398829d64c9f5f40d96e /apt-pkg/contrib/fileutl.cc
parente5f2e875e53cf03112dda0ac72ab252ca9b2b377 (diff)
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. (cherry picked from commit 15fe8e62d37bc87114c59d385bed7ceefb72886b)
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r--apt-pkg/contrib/fileutl.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index b8409c35d..20ccaa1c6 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1882,11 +1882,12 @@ public:
return filefd->FileFdError("ReadWrite mode is not supported for file %s", filefd->FileName.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;