[poppler] poppler/Form.cc poppler/SignatureHandler.cc poppler/SignatureHandler.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Mar 20 12:07:15 UTC 2023


 poppler/Form.cc             |    6 +++---
 poppler/SignatureHandler.cc |    7 +++----
 poppler/SignatureHandler.h  |    3 ++-
 3 files changed, 8 insertions(+), 8 deletions(-)

New commits:
commit e5a3052390b5912b19c749e91babfe3d83004184
Author: Sune Vuorela <sune at vuorela.dk>
Date:   Thu Mar 16 10:20:22 2023 +0100

    Use vector, not malloc/free for signature data

diff --git a/poppler/Form.cc b/poppler/Form.cc
index 3d594598..11ee776f 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -2356,9 +2356,9 @@ SignatureInfo *FormFieldSignature::validateSignature(bool doVerifyCert, bool for
     }
 
     const int signature_len = signature->getLength();
-    unsigned char *signatureuchar = (unsigned char *)gmalloc(signature_len);
-    memcpy(signatureuchar, signature->c_str(), signature_len);
-    SignatureHandler signature_handler(signatureuchar, signature_len);
+    std::vector<unsigned char> signatureData(signature_len);
+    memcpy(signatureData.data(), signature->c_str(), signature_len);
+    SignatureHandler signature_handler(std::move(signatureData));
 
     Goffset fileLength = doc->getBaseStream()->getLength();
     for (int i = 0; i < arrayLen / 2; i++) {
diff --git a/poppler/SignatureHandler.cc b/poppler/SignatureHandler.cc
index cf6ee95d..4aa02297 100644
--- a/poppler/SignatureHandler.cc
+++ b/poppler/SignatureHandler.cc
@@ -799,11 +799,11 @@ void SignatureHandler::setNSSPasswordCallback(const std::function<char *(const c
     PasswordFunction = f;
 }
 
-SignatureHandler::SignatureHandler(unsigned char *p7, int p7_length) : hash_context(nullptr), CMSMessage(nullptr), CMSSignedData(nullptr), CMSSignerInfo(nullptr), signing_cert(nullptr)
+SignatureHandler::SignatureHandler(std::vector<unsigned char> &&p7data) : p7(std::move(p7data)), hash_context(nullptr), CMSMessage(nullptr), CMSSignedData(nullptr), CMSSignerInfo(nullptr), signing_cert(nullptr)
 {
     setNSSDir({});
-    CMSitem.data = p7;
-    CMSitem.len = p7_length;
+    CMSitem.data = p7.data();
+    CMSitem.len = p7.size();
     CMSMessage = CMS_MessageCreate(&CMSitem);
     CMSSignedData = CMS_SignedDataCreate(CMSMessage);
     if (CMSSignedData) {
@@ -846,7 +846,6 @@ void SignatureHandler::restartHash()
 
 SignatureHandler::~SignatureHandler()
 {
-    SECITEM_FreeItem(&CMSitem, PR_FALSE);
     if (CMSMessage) {
         // in the CMS_SignedDataCreate, we malloc some memory
         // inside the CMSSignedData structure
diff --git a/poppler/SignatureHandler.h b/poppler/SignatureHandler.h
index 5a7399d1..0174c6e8 100644
--- a/poppler/SignatureHandler.h
+++ b/poppler/SignatureHandler.h
@@ -46,7 +46,7 @@
 class POPPLER_PRIVATE_EXPORT SignatureHandler
 {
 public:
-    SignatureHandler(unsigned char *p7, int p7_length);
+    explicit SignatureHandler(std::vector<unsigned char> &&p7data);
     SignatureHandler(const std::string &certNickName, HashAlgorithm digestAlgTag);
     ~SignatureHandler();
     time_t getSigningTime() const;
@@ -81,6 +81,7 @@ private:
     HASHContext *initHashContext();
     static void outputCallback(void *arg, const char *buf, unsigned long len);
 
+    std::vector<unsigned char> p7;
     unsigned int hash_length;
     HashAlgorithm digest_alg_tag;
     SECItem CMSitem;


More information about the poppler mailing list