diff options
author | ian.mcgreer%sun.com <devnull@localhost> | 2003-05-12 23:24:25 +0000 |
---|---|---|
committer | ian.mcgreer%sun.com <devnull@localhost> | 2003-05-12 23:24:25 +0000 |
commit | 3cea0422e0365e6ccae07798f476540874e4b3c0 (patch) | |
tree | 07c759f88f6bf478bf034890a038bd30a3d78253 | |
parent | 12361a78bd390cee75e84f2d6959c2a9bf0cbacc (diff) | |
parent | 005096279bb195a2ca2b0f5a29e7a56f7d1832a2 (diff) | |
download | nss-hg-3cea0422e0365e6ccae07798f476540874e4b3c0.tar.gz |
bug 203049, move operations outside of slot->slotLock
r=relyea
-rw-r--r-- | security/nss/lib/softoken/pkcs11.c | 31 | ||||
-rw-r--r-- | security/nss/lib/softoken/pkcs11i.h | 2 |
2 files changed, 16 insertions, 17 deletions
diff --git a/security/nss/lib/softoken/pkcs11.c b/security/nss/lib/softoken/pkcs11.c index 55c6ad26c..992feda19 100644 --- a/security/nss/lib/softoken/pkcs11.c +++ b/security/nss/lib/softoken/pkcs11.c @@ -2916,16 +2916,16 @@ CK_RV NSC_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, flags | CKF_SERIAL_SESSION); if (session == NULL) return CKR_HOST_MEMORY; - PK11_USE_THREADS(PZ_Lock(slot->slotLock);) if (slotID == NETSCAPE_SLOT_ID && (flags & CKF_RW_SESSION)) { /* NETSCAPE_SLOT_ID is Read ONLY */ session->info.flags &= ~CKF_RW_SESSION; } - slot->sessionCount++; + PK11_USE_THREADS(PZ_Lock(slot->slotLock);) + ++slot->sessionCount; + PK11_USE_THREADS(PZ_Unlock(slot->slotLock);) if (session->info.flags & CKF_RW_SESSION) { - slot->rwSessionCount++; + PR_AtomicIncrement(&slot->rwSessionCount); } - PK11_USE_THREADS(PZ_Unlock(slot->slotLock);) do { do { @@ -2975,19 +2975,18 @@ CK_RV NSC_CloseSession(CK_SESSION_HANDLE hSession) } PK11_USE_THREADS(PZ_Unlock(PK11_SESSION_LOCK(slot,hSession));) - PK11_USE_THREADS(PZ_Lock(slot->slotLock);) if (sessionFound) { - slot->sessionCount--; + PK11_USE_THREADS(PZ_Lock(slot->slotLock);) + if (--slot->sessionCount == 0) { + pw = slot->password; + slot->isLoggedIn = PR_FALSE; + slot->password = NULL; + } + PK11_USE_THREADS(PZ_Unlock(slot->slotLock);) if (session->info.flags & CKF_RW_SESSION) { - slot->rwSessionCount--; + PR_AtomicDecrement(&slot->rwSessionCount); } } - if (slot->sessionCount == 0) { - pw = slot->password; - slot->isLoggedIn = PR_FALSE; - slot->password = NULL; - } - PK11_USE_THREADS(PZ_Unlock(slot->slotLock);) pk11_FreeSession(session); if (pw) SECITEM_ZfreeItem(pw, PR_TRUE); @@ -3033,11 +3032,11 @@ CK_RV NSC_CloseAllSessions (CK_SLOT_ID slotID) session->next = session->prev = NULL; PK11_USE_THREADS(PZ_Unlock(PK11_SESSION_LOCK(slot,i));) PK11_USE_THREADS(PZ_Lock(slot->slotLock);) - slot->sessionCount--; + --slot->sessionCount; + PK11_USE_THREADS(PZ_Unlock(slot->slotLock);) if (session->info.flags & CKF_RW_SESSION) { - slot->rwSessionCount--; + PR_AtomicDecrement(&slot->rwSessionCount); } - PK11_USE_THREADS(PZ_Unlock(slot->slotLock);) } else { PK11_USE_THREADS(PZ_Unlock(PK11_SESSION_LOCK(slot,i));) } diff --git a/security/nss/lib/softoken/pkcs11i.h b/security/nss/lib/softoken/pkcs11i.h index 72b0a6674..67f11c3aa 100644 --- a/security/nss/lib/softoken/pkcs11i.h +++ b/security/nss/lib/softoken/pkcs11i.h @@ -291,7 +291,7 @@ struct PK11SlotStr { int sessionIDCount; int sessionIDConflict; int sessionCount; - int rwSessionCount; + PRInt32 rwSessionCount; int tokenIDCount; PK11Object *tokObjects[TOKEN_OBJECT_HASH_SIZE]; PK11Session *head[SESSION_HASH_SIZE]; |