From cde5ee8fe527d3d672775909d27110d11c393774 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 4 Feb 2019 14:43:16 +0100 Subject: gpgv: Use buffered writes for splitting clearsigned files This is safe here, as the code ensures that the file is flushed before it is being used. The next series should probably make GetTempFile() buffer writes by default. --- apt-pkg/contrib/fileutl.cc | 6 +++++- apt-pkg/contrib/fileutl.h | 6 ++++++ apt-pkg/contrib/gpgv.cc | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 8cb4b509c..0c0cb05ea 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -3106,6 +3106,10 @@ std::string GetTempDir(std::string const &User) } /*}}}*/ FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * const TmpFd) /*{{{*/ +{ + return GetTempFile(Prefix, ImmediateUnlink, TmpFd, false); +} +FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * const TmpFd, bool Buffered) { char fn[512]; FileFd * const Fd = TmpFd == nullptr ? new FileFd() : TmpFd; @@ -3123,7 +3127,7 @@ FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * co delete Fd; return nullptr; } - if (!Fd->OpenDescriptor(fd, FileFd::ReadWrite, FileFd::None, true)) + if (!Fd->OpenDescriptor(fd, FileFd::ReadWrite | (Buffered ? FileFd::BufferedWrite : 0), FileFd::None, true)) { _error->Errno("GetTempFile",_("Unable to write to %s"),fn); if (TmpFd == nullptr) diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index c7927951f..862880c31 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -210,6 +210,12 @@ FileFd* GetTempFile(std::string const &Prefix = "", bool ImmediateUnlink = true, FileFd * const TmpFd = NULL); +// FIXME: GetTempFile should always return a buffered file +FileFd* GetTempFile(std::string const &Prefix, + bool ImmediateUnlink , + FileFd * const TmpFd, + bool Buffered) APT_HIDDEN; + /** \brief Ensure the existence of the given Path * * \param Parent directory of the Path directory - a trailing diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc index b845528d8..35d859849 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -535,7 +535,8 @@ bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile, /*}}}*/ bool OpenMaybeClearSignedFile(std::string const &ClearSignedFileName, FileFd &MessageFile) /*{{{*/ { - if (GetTempFile("clearsigned.message", true, &MessageFile) == nullptr) + // Buffered file + if (GetTempFile("clearsigned.message", true, &MessageFile, true) == nullptr) return false; if (MessageFile.Failed()) return _error->Error("Couldn't open temporary file to work with %s", ClearSignedFileName.c_str()); -- cgit v1.2.3