From 2077c5e4e10a8254206945520f084e6216464d6a Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 15 Oct 2018 10:14:04 +0200 Subject: xmlsecurity: prevent seg. fault if there is no private key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8c6917c63bbdcf0d9bb2eb1c89745186feb263f8 Reviewed-on: https://gerrit.libreoffice.org/61781 Reviewed-by: Tomaž Vajngerl Tested-by: Tomaž Vajngerl --- .../source/xmlsec/nss/securityenvironment_nssimpl.cxx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'xmlsecurity') diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx index 86d68c522ed7..cae2675db64a 100644 --- a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx @@ -816,11 +816,18 @@ xmlSecKeysMngrPtr SecurityEnvironment_NssImpl::createKeysManager() { { if (auto pCERTCertificate = const_cast(pCertificate->getNssCert())) { - SECKEYPrivateKey* pPrivateKey = PK11_FindPrivateKeyFromCert(pCERTCertificate->slot, pCERTCertificate, nullptr); - xmlSecKeyDataPtr pKeyData = xmlSecNssPKIAdoptKey(pPrivateKey, nullptr); - xmlSecKeyPtr pKey = xmlSecKeyCreate(); - xmlSecKeySetValue(pKey, pKeyData); - xmlSecNssAppDefaultKeysMngrAdoptKey(pKeysMngr, pKey); + if (pCERTCertificate && pCERTCertificate->slot) + { + SECKEYPrivateKey* pPrivateKey = PK11_FindPrivateKeyFromCert(pCERTCertificate->slot, pCERTCertificate, nullptr); + xmlSecKeyDataPtr pKeyData = xmlSecNssPKIAdoptKey(pPrivateKey, nullptr); + xmlSecKeyPtr pKey = xmlSecKeyCreate(); + xmlSecKeySetValue(pKey, pKeyData); + xmlSecNssAppDefaultKeysMngrAdoptKey(pKeysMngr, pKey); + } + else + { + SAL_WARN("xmlsecurity.xmlsec", "Can't get the private key from the certificate."); + } } } -- cgit