From 487a4aee3026148c3b603c9700c55719d9d0a6f5 Mon Sep 17 00:00:00 2001 From: "nelson%bolyard.com" Date: Sat, 13 Jan 2007 23:41:21 +0000 Subject: [PATCH] Bug 366405. Fix PK11_DeleteTokenPrivateKey to not leak the cert when force is true. r=alexei.volkov,wtchang git-svn-id: svn://10.0.0.236/branches/NSS_3_11_BRANCH@218280 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/security/nss/lib/pk11wrap/pk11akey.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mozilla/security/nss/lib/pk11wrap/pk11akey.c b/mozilla/security/nss/lib/pk11wrap/pk11akey.c index 9692d971ff4..707989d9fc3 100644 --- a/mozilla/security/nss/lib/pk11wrap/pk11akey.c +++ b/mozilla/security/nss/lib/pk11wrap/pk11akey.c @@ -1671,18 +1671,17 @@ SECStatus PK11_DeleteTokenPrivateKey(SECKEYPrivateKey *privKey, PRBool force) { CERTCertificate *cert=PK11_GetCertFromPrivateKey(privKey); + SECStatus rv = SECWouldBlock; - /* found a cert matching the private key?. */ - if (!force && cert != NULL) { - /* yes, don't delete the key */ - CERT_DestroyCertificate(cert); - SECKEY_DestroyPrivateKey(privKey); - return SECWouldBlock; + if (!cert || force) { + /* now, then it's safe for the key to go away */ + rv = PK11_DestroyTokenObject(privKey->pkcs11Slot,privKey->pkcs11ID); + } + if (cert) { + CERT_DestroyCertificate(cert); } - /* now, then it's safe for the key to go away */ - PK11_DestroyTokenObject(privKey->pkcs11Slot,privKey->pkcs11ID); SECKEY_DestroyPrivateKey(privKey); - return SECSuccess; + return rv; } /*