diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2013-05-25 20:33:15 +0200 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2013-06-09 15:12:32 +0200 |
commit | f97bb5237489134cb971ce38b93c5d6220341ea8 (patch) | |
tree | eabfd141e20fd499bbad1c0b0385eca41cf24229 | |
parent | bf35c19b817cc1474b3deabce0b0953c248bad42 (diff) |
OpenDescriptor should autoclose fd always on error
OpenInternDescriptor failures would cause additional errors to be
generated by double-closing an fd. Other errors (although these
are generated if the method is used incorrectly, so unlikely)
didn't close the fd aswell.
Closes: 704608
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 23 | ||||
-rw-r--r-- | debian/changelog | 1 |
2 files changed, 20 insertions, 4 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 4a7299e99..7c3a302e2 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1010,14 +1010,19 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, CompressMode Compre case Xz: name = "xz"; break; case Auto: case Extension: + if (AutoClose == true && Fd != -1) + close(Fd); return FileFdError("Opening Fd %d in Auto or Extension compression mode is not supported", Fd); } for (; compressor != compressors.end(); ++compressor) if (compressor->Name == name) break; if (compressor == compressors.end()) + { + if (AutoClose == true && Fd != -1) + close(Fd); return FileFdError("Can't find a configured compressor %s for file %s", name.c_str(), FileName.c_str()); - + } return OpenDescriptor(Fd, Mode, *compressor, AutoClose); } bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration::Compressor const &compressor, bool AutoClose) @@ -1039,11 +1044,21 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration: else iFd = Fd; this->FileName = ""; - if (OpenInternDescriptor(Mode, compressor) == false) + if (Fd == -1 || OpenInternDescriptor(Mode, compressor) == false) { - if (AutoClose) + if (iFd != -1 && ( +#ifdef HAVE_ZLIB + compressor.Name == "gzip" || +#endif +#ifdef HAVE_BZ2 + compressor.Name == "bzip2" || +#endif + AutoClose == true)) + { close (iFd); - return FileFdErrno("gzdopen",_("Could not open file descriptor %d"), Fd); + iFd = -1; + } + return FileFdError(_("Could not open file descriptor %d"), Fd); } return true; } diff --git a/debian/changelog b/debian/changelog index a80bac3d7..42a8e540e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,6 +12,7 @@ apt (0.9.8.3) UNRELEASED; urgency=low * fix support for multiple patterns in apt-cache search (Closes: #691453) * set Fail flag in FileFd on all errors consistently * don't explicitly init ExtractTar InFd with invalid fd + * OpenDescriptor should autoclose fd always on error (Closes: #704608) -- David Kalnischkies <kalnischkies@gmail.com> Sun, 09 Jun 2013 15:06:24 +0200 |