X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/b408e4ad0010b273dac0af7dc87ab61062d89e49..3b5607fc31371190470074371793cb8500b5139e:/apt-pkg/contrib/gpgv.cc diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc index 54cc4c6d0..f24dd9640 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -2,35 +2,31 @@ // Include Files /*{{{*/ #include +#include +#include +#include +#include +#include + #include #include #include #include #include -#include -#include #include - -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include /*}}}*/ static char * GenerateTemporaryFileTemplate(const char *basename) /*{{{*/ { - const char *tmpdir = getenv("TMPDIR"); -#ifdef P_tmpdir - if (!tmpdir) - tmpdir = P_tmpdir; -#endif - if (!tmpdir) - tmpdir = "/tmp"; - std::string out; - strprintf(out, "%s/%s.XXXXXX", tmpdir, basename); + std::string tmpdir = GetTempDir(); + strprintf(out, "%s/%s.XXXXXX", tmpdir.c_str(), basename); return strdup(out.c_str()); } /*}}}*/ @@ -109,12 +105,12 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, } } + enum { DETACHED, CLEARSIGNED } releaseSignature = (FileGPG != File) ? DETACHED : CLEARSIGNED; std::vector dataHeader; char * sig = NULL; char * data = NULL; - // file with detached signature - if (FileGPG != File) + if (releaseSignature == DETACHED) { Args.push_back(FileGPG.c_str()); Args.push_back(File.c_str()); @@ -154,7 +150,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, if (sigFd != -1) unlink(data); ioprintf(std::cerr, "Splitting up %s into data and signature failed", File.c_str()); - exit(EINTERNAL); + exit(112); } Args.push_back(sig); Args.push_back(data); @@ -187,7 +183,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, putenv((char *)"LC_MESSAGES="); } - if (FileGPG != File) + if (releaseSignature == DETACHED) { execvp(gpgvpath.c_str(), (char **) &Args[0]); ioprintf(std::cerr, "Couldn't execute %s to check %s", Args[0], File.c_str()); @@ -266,8 +262,7 @@ bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile, char *buf = NULL; size_t buf_size = 0; - ssize_t line_len = 0; - while ((line_len = getline(&buf, &buf_size, in)) != -1) + while (getline(&buf, &buf_size, in) != -1) { _strrstrip(buf); if (found_message_start == false) @@ -298,20 +293,21 @@ bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile, SignatureFile->Write("\n", 1); } } - else if (found_message_end == false) + else if (found_message_end == false) // we are in the message block { - // we are in the message block + // we don't have any fields which need dash-escaped, + // but implementations are free to encode all lines … + char const * dashfree = buf; + if (strncmp(dashfree, "- ", 2) == 0) + dashfree += 2; if(first_line == true) // first line does not need a newline - { - if (ContentFile != NULL) - ContentFile->Write(buf, strlen(buf)); first_line = false; - } else if (ContentFile != NULL) - { ContentFile->Write("\n", 1); - ContentFile->Write(buf, strlen(buf)); - } + else + continue; + if (ContentFile != NULL) + ContentFile->Write(dashfree, strlen(dashfree)); } } else if (found_signature == true) @@ -333,11 +329,11 @@ bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile, // if we haven't found any of them, this an unsigned file, // so don't generate an error, but splitting was unsuccessful none-the-less - if (found_message_start == false && found_message_end == false) + if (first_line == true && found_message_start == false && found_message_end == false) return false; // otherwise one missing indicates a syntax error - else if (found_message_start == false || found_message_end == false) - return _error->Error("Splitting of file %s failed as it doesn't contain all expected parts", InFile.c_str()); + else if (first_line == true || found_message_start == false || found_message_end == false) + return _error->Error("Splitting of file %s failed as it doesn't contain all expected parts %i %i %i", InFile.c_str(), first_line, found_message_start, found_message_end); return true; } @@ -360,7 +356,7 @@ bool OpenMaybeClearSignedFile(std::string const &ClearSignedFileName, FileFd &Me return _error->Error("Couldn't open temporary file to work with %s", ClearSignedFileName.c_str()); _error->PushToStack(); - bool const splitDone = SplitClearSignedFile(ClearSignedFileName.c_str(), &MessageFile, NULL, NULL); + bool const splitDone = SplitClearSignedFile(ClearSignedFileName, &MessageFile, NULL, NULL); bool const errorDone = _error->PendingError(); _error->MergeWithStack(); if (splitDone == false)