summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/fileutl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r--apt-pkg/contrib/fileutl.cc27
1 files changed, 21 insertions, 6 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index d3764d003..f8f7a478c 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -43,6 +43,7 @@
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
+#include <stdio.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/time.h>
@@ -928,17 +929,31 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap)
// StartsWithGPGClearTextSignature - Check if a file is Pgp/GPG clearsigned /*{{{*/
bool StartsWithGPGClearTextSignature(string const &FileName)
{
- static const char* SIGMSG = "-----BEGIN PGP SIGNED MESSAGE-----\n";
- char buffer[strlen(SIGMSG)+1];
FILE* gpg = fopen(FileName.c_str(), "r");
- if (gpg == NULL)
+ if (gpg == nullptr)
return false;
- char const * const test = fgets(buffer, sizeof(buffer), gpg);
- fclose(gpg);
- if (test == NULL || strcmp(buffer, SIGMSG) != 0)
+ char * lineptr = nullptr;
+ size_t n = 0;
+ errno = 0;
+ ssize_t const result = getline(&lineptr, &n, gpg);
+ if (errno != 0)
+ {
+ _error->Errno("getline", "Could not read from %s", FileName.c_str());
+ fclose(gpg);
+ free(lineptr);
return false;
+ }
+ fclose(gpg);
+ _strrstrip(lineptr);
+ static const char* SIGMSG = "-----BEGIN PGP SIGNED MESSAGE-----";
+ if (result == -1 || strcmp(lineptr, SIGMSG) != 0)
+ {
+ free(lineptr);
+ return false;
+ }
+ free(lineptr);
return true;
}
/*}}}*/