[poppler] poppler/NSSCryptoSignBackend.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 27 22:04:47 UTC 2023


 poppler/NSSCryptoSignBackend.cc |   40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

New commits:
commit 2c403ec533ad9ad821c37e3f80f8f361ce9cdea8
Author: Albert Astals Cid <aacid at kde.org>
Date:   Mon Jun 26 00:51:22 2023 +0200

    Fix crash if CERT_ExtractPublicKey doesn't return a public key
    
    Fixes KDE Bug #471422

diff --git a/poppler/NSSCryptoSignBackend.cc b/poppler/NSSCryptoSignBackend.cc
index 108bff2a..6e9c1396 100644
--- a/poppler/NSSCryptoSignBackend.cc
+++ b/poppler/NSSCryptoSignBackend.cc
@@ -616,33 +616,37 @@ static std::unique_ptr<X509CertificateInfo> getCertificateInfoFromCERT(CERTCerti
     // public key info
     X509CertificateInfo::PublicKeyInfo pkInfo;
     SECKEYPublicKey *pk = CERT_ExtractPublicKey(cert);
-    switch (pk->keyType) {
-    case rsaKey:
-        pkInfo.publicKey = SECItemToGooString(pk->u.rsa.modulus);
-        pkInfo.publicKeyType = RSAKEY;
-        break;
-    case dsaKey:
-        pkInfo.publicKey = SECItemToGooString(pk->u.dsa.publicValue);
-        pkInfo.publicKeyType = DSAKEY;
-        break;
-    case ecKey:
-        pkInfo.publicKey = SECItemToGooString(pk->u.ec.publicValue);
-        pkInfo.publicKeyType = ECKEY;
-        break;
-    default:
+    if (pk) {
+        switch (pk->keyType) {
+        case rsaKey:
+            pkInfo.publicKey = SECItemToGooString(pk->u.rsa.modulus);
+            pkInfo.publicKeyType = RSAKEY;
+            break;
+        case dsaKey:
+            pkInfo.publicKey = SECItemToGooString(pk->u.dsa.publicValue);
+            pkInfo.publicKeyType = DSAKEY;
+            break;
+        case ecKey:
+            pkInfo.publicKey = SECItemToGooString(pk->u.ec.publicValue);
+            pkInfo.publicKeyType = ECKEY;
+            break;
+        default:
+            pkInfo.publicKey = SECItemToGooString(cert->subjectPublicKeyInfo.subjectPublicKey);
+            pkInfo.publicKeyType = OTHERKEY;
+            break;
+        }
+        pkInfo.publicKeyStrength = SECKEY_PublicKeyStrengthInBits(pk);
+        SECKEY_DestroyPublicKey(pk);
+    } else {
         pkInfo.publicKey = SECItemToGooString(cert->subjectPublicKeyInfo.subjectPublicKey);
         pkInfo.publicKeyType = OTHERKEY;
-        break;
     }
-    pkInfo.publicKeyStrength = SECKEY_PublicKeyStrengthInBits(pk);
     certInfo->setPublicKeyInfo(std::move(pkInfo));
 
     certInfo->setKeyUsageExtensions(cert->keyUsage);
     certInfo->setCertificateDER(SECItemToGooString(cert->derCert));
     certInfo->setIsSelfSigned(CERT_CompareName(&cert->subject, &cert->issuer) == SECEqual);
 
-    SECKEY_DestroyPublicKey(pk);
-
     return certInfo;
 }
 


More information about the poppler mailing list