summaryrefslogtreecommitdiff
path: root/oox/source/crypto/CryptTools.cxx
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-11-29 16:15:04 +0000
committerCaolán McNamara <caolanm@redhat.com>2017-11-30 10:41:54 +0100
commitb784de0b99cff92ac34d33a257e225d11d101ec5 (patch)
treeb5caf23ba4eebdfe540ac82b007b282443004e9c /oox/source/crypto/CryptTools.cxx
parentcdbaef860bddaf4cc4d58b210c87e2a6b28c5cac (diff)
ofz: handle bad key len and subsequent PK11_ImportSymKey failure
Change-Id: Ied93745f924cbcbc674b5c9a78545aa1f79fc61e Reviewed-on: https://gerrit.libreoffice.org/45514 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'oox/source/crypto/CryptTools.cxx')
-rw-r--r--oox/source/crypto/CryptTools.cxx12
1 files changed, 9 insertions, 3 deletions
diff --git a/oox/source/crypto/CryptTools.cxx b/oox/source/crypto/CryptTools.cxx
index 2c7c5f794fa3..6de4363c59f4 100644
--- a/oox/source/crypto/CryptTools.cxx
+++ b/oox/source/crypto/CryptTools.cxx
@@ -34,9 +34,12 @@ Crypto::~Crypto()
EVP_CIPHER_CTX_cleanup( &mContext );
#endif
#if USE_TLS_NSS
- PK11_DestroyContext( mContext, PR_TRUE );
- PK11_FreeSymKey( mSymKey );
- SECITEM_FreeItem( mSecParam, PR_TRUE );
+ if (mContext)
+ PK11_DestroyContext(mContext, PR_TRUE);
+ if (mSymKey)
+ PK11_FreeSymKey(mSymKey);
+ if (mSecParam)
+ SECITEM_FreeItem(mSecParam, PR_TRUE);
#endif
}
@@ -101,6 +104,9 @@ void Crypto::setupContext(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& i
keyItem.len = key.size();
mSymKey = PK11_ImportSymKey(pSlot, mechanism, PK11_OriginUnwrap, CKA_ENCRYPT, &keyItem, nullptr);
+ if (!mSymKey)
+ throw css::uno::RuntimeException("NSS SymKey failure", css::uno::Reference<css::uno::XInterface>());
+
mSecParam = PK11_ParamFromIV(mechanism, pIvItem);
mContext = PK11_CreateContextBySymKey(mechanism, operation, mSymKey, mSecParam);
}