diff options
author | Tim Taubert <ttaubert@mozilla.com> | 2017-05-29 16:06:46 +0200 |
---|---|---|
committer | Tim Taubert <ttaubert@mozilla.com> | 2017-05-29 16:06:46 +0200 |
commit | b4a5f4d76ae30be0a830a2b009b18c60160802e8 (patch) | |
tree | 753e5d0da00c53ad272b695730e38eb5a0b0c9a5 | |
parent | 522c82de28794be1a0f82eae678e60d7cd37d7f3 (diff) | |
download | nss-hg-b4a5f4d76ae30be0a830a2b009b18c60160802e8.tar.gz |
Bug 1273678 - Own PK11SlotInfos in NSSSlot/NSSToken r=franziskus (thx=keeler)
Differential Revision: https://nss-review.dev.mozaws.net/D332
-rw-r--r-- | lib/dev/devslot.c | 14 | ||||
-rw-r--r-- | lib/dev/devtoken.c | 11 | ||||
-rw-r--r-- | lib/pk11wrap/dev3hack.c | 4 |
3 files changed, 21 insertions, 8 deletions
diff --git a/lib/dev/devslot.c b/lib/dev/devslot.c index c3c05be9a..7e8bfcd64 100644 --- a/lib/dev/devslot.c +++ b/lib/dev/devslot.c @@ -31,6 +31,7 @@ nssSlot_Destroy( { if (slot) { if (PR_ATOMIC_DECREMENT(&slot->base.refCount) == 0) { + PK11_FreeSlot(slot->pk11slot); PZ_DestroyLock(slot->base.lock); return nssArena_Destroy(slot->base.arena); } @@ -224,10 +225,17 @@ NSS_IMPLEMENT NSSToken * nssSlot_GetToken( NSSSlot *slot) { - if (nssSlot_IsTokenPresent(slot)) { - return nssToken_AddRef(slot->token); + NSSToken *rvToken = NULL; + nssSlot_EnterMonitor(slot); + + /* Even if a token should be present, check `slot->token` too as it + * might be gone already. This would happen mostly on shutdown. */ + if (nssSlot_IsTokenPresent(slot) && slot->token) { + rvToken = nssToken_AddRef(slot->token); } - return (NSSToken *)NULL; + + nssSlot_ExitMonitor(slot); + return rvToken; } NSS_IMPLEMENT PRStatus diff --git a/lib/dev/devtoken.c b/lib/dev/devtoken.c index 40f2acaae..0d4c3b5a7 100644 --- a/lib/dev/devtoken.c +++ b/lib/dev/devtoken.c @@ -29,11 +29,16 @@ nssToken_Destroy( { if (tok) { if (PR_ATOMIC_DECREMENT(&tok->base.refCount) == 0) { + PK11_FreeSlot(tok->pk11slot); PZ_DestroyLock(tok->base.lock); nssTokenObjectCache_Destroy(tok->cache); - /* The token holds the first/last reference to the slot. - * When the token is actually destroyed, that ref must go too. - */ + + /* We're going away, let the nssSlot know in case it's held + * alive by someone else. Usually we should hold the last ref. */ + nssSlot_EnterMonitor(tok->slot); + tok->slot->token = NULL; + nssSlot_ExitMonitor(tok->slot); + (void)nssSlot_Destroy(tok->slot); return nssArena_Destroy(tok->base.arena); } diff --git a/lib/pk11wrap/dev3hack.c b/lib/pk11wrap/dev3hack.c index 27325a55a..39afd6743 100644 --- a/lib/pk11wrap/dev3hack.c +++ b/lib/pk11wrap/dev3hack.c @@ -114,7 +114,7 @@ nssSlot_CreateFromPK11SlotInfo(NSSTrustDomain *td, PK11SlotInfo *nss3slot) rvSlot->base.refCount = 1; rvSlot->base.lock = PZ_NewLock(nssILockOther); rvSlot->base.arena = arena; - rvSlot->pk11slot = nss3slot; + rvSlot->pk11slot = PK11_ReferenceSlot(nss3slot); rvSlot->epv = nss3slot->functionList; rvSlot->slotID = nss3slot->slotID; /* Grab the slot name from the PKCS#11 fixed-length buffer */ @@ -150,7 +150,7 @@ nssToken_CreateFromPK11SlotInfo(NSSTrustDomain *td, PK11SlotInfo *nss3slot) return NULL; } rvToken->base.arena = arena; - rvToken->pk11slot = nss3slot; + rvToken->pk11slot = PK11_ReferenceSlot(nss3slot); rvToken->epv = nss3slot->functionList; rvToken->defaultSession = nssSession_ImportNSS3Session(td->arena, nss3slot->session, |