|
@@ -0,0 +1,75 @@
|
|
|
+From 33672ca1b6670f7378e24f6d475438f7f5d86b05 Mon Sep 17 00:00:00 2001
|
|
|
+From: Sune Vuorela <sune@vuorela.dk>
|
|
|
+Date: Mon, 22 May 2023 19:53:08 +0000
|
|
|
+Subject: [PATCH] Fix crash with weird hashing used for signatures
|
|
|
+
|
|
|
+CVE: CVE-2025-43903
|
|
|
+Upstream-Status: Backport [https://gitlab.freedesktop.org/poppler/poppler/-/commit/33672ca1b6670f7378e24f6d475438f7f5d86b05]
|
|
|
+
|
|
|
+Signed-off-by: Yogita Urade <yogita.urade@windriver.com>
|
|
|
+---
|
|
|
+ poppler/SignatureHandler.cc | 15 ++++++++++++---
|
|
|
+ poppler/SignatureHandler.h | 7 ++++++-
|
|
|
+ 2 files changed, 18 insertions(+), 4 deletions(-)
|
|
|
+
|
|
|
+diff --git a/poppler/SignatureHandler.cc b/poppler/SignatureHandler.cc
|
|
|
+index 9916300..f0b7006 100644
|
|
|
+--- a/poppler/SignatureHandler.cc
|
|
|
++++ b/poppler/SignatureHandler.cc
|
|
|
+@@ -768,11 +768,11 @@ SignatureVerificationHandler::SignatureVerificationHandler(std::vector<unsigned
|
|
|
+ SECItem usedAlgorithm = NSS_CMSSignedData_GetDigestAlgs(CMSSignedData)[0]->algorithm;
|
|
|
+ auto hashAlgorithm = SECOID_FindOIDTag(&usedAlgorithm);
|
|
|
+ HASH_HashType hashType = HASH_GetHashTypeByOidTag(hashAlgorithm);
|
|
|
+- hashContext = std::make_unique<HashContext>(ConvertHashTypeFromNss(hashType));
|
|
|
++ hashContext = HashContext::create(ConvertHashTypeFromNss(hashType));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+-SignatureSignHandler::SignatureSignHandler(const std::string &certNickname, HashAlgorithm digestAlgTag) : hashContext(std::make_unique<HashContext>(digestAlgTag)), signing_cert(nullptr)
|
|
|
++SignatureSignHandler::SignatureSignHandler(const std::string &certNickname, HashAlgorithm digestAlgTag) : hashContext(HashContext::create(digestAlgTag)), signing_cert(nullptr)
|
|
|
+ {
|
|
|
+ SignatureHandler::setNSSDir({});
|
|
|
+ signing_cert = CERT_FindCertByNickname(CERT_GetDefaultCertDB(), certNickname.c_str());
|
|
|
+@@ -1232,7 +1232,16 @@ std::vector<unsigned char> HashContext::endHash()
|
|
|
+ return digestBuffer;
|
|
|
+ }
|
|
|
+
|
|
|
+-HashContext::HashContext(HashAlgorithm algorithm) : hash_context { HASH_Create(HASH_GetHashTypeByOidTag(ConvertHashAlgorithmToNss(algorithm))) }, digest_alg_tag(algorithm) { }
|
|
|
++HashContext::HashContext(HashAlgorithm algorithm, private_tag) : hash_context { HASH_Create(HASH_GetHashTypeByOidTag(ConvertHashAlgorithmToNss(algorithm))) }, digest_alg_tag(algorithm) { }
|
|
|
++
|
|
|
++std::unique_ptr<HashContext> HashContext::create(HashAlgorithm algorithm)
|
|
|
++{
|
|
|
++ auto ctx = std::make_unique<HashContext>(algorithm, private_tag {});
|
|
|
++ if (ctx->hash_context) {
|
|
|
++ return ctx;
|
|
|
++ }
|
|
|
++ return {};
|
|
|
++}
|
|
|
+
|
|
|
+ HashAlgorithm HashContext::getHashAlgorithm() const
|
|
|
+ {
|
|
|
+diff --git a/poppler/SignatureHandler.h b/poppler/SignatureHandler.h
|
|
|
+index c9fb575..f1b319f 100644
|
|
|
+--- a/poppler/SignatureHandler.h
|
|
|
++++ b/poppler/SignatureHandler.h
|
|
|
+@@ -51,12 +51,17 @@ static const int maxSupportedSignatureSize = 10000;
|
|
|
+
|
|
|
+ class HashContext
|
|
|
+ {
|
|
|
++ class private_tag
|
|
|
++ {
|
|
|
++ };
|
|
|
++
|
|
|
+ public:
|
|
|
+- explicit HashContext(HashAlgorithm algorithm);
|
|
|
++ HashContext(HashAlgorithm algorithm, private_tag);
|
|
|
+ void updateHash(unsigned char *data_block, int data_len);
|
|
|
+ std::vector<unsigned char> endHash();
|
|
|
+ HashAlgorithm getHashAlgorithm() const;
|
|
|
+ ~HashContext() = default;
|
|
|
++ static std::unique_ptr<HashContext> create(HashAlgorithm algorithm);
|
|
|
+
|
|
|
+ private:
|
|
|
+ struct HashDestroyer
|
|
|
+--
|
|
|
+2.40.0
|