bug 191757, InitOIDHash() not threadsafe

r=relyea
This commit is contained in:
ian.mcgreer%sun.com 2003-02-28 21:13:20 +00:00
Родитель 5564f4e0cf
Коммит cccb7a3f68
3 изменённых файлов: 26 добавлений и 17 удалений

Просмотреть файл

@ -32,7 +32,7 @@
* may use your version of this file under either the MPL or the * may use your version of this file under either the MPL or the
* GPL. * GPL.
* *
# $Id: nssinit.c,v 1.61 2003-02-20 16:58:53 wtc%netscape.com Exp $ # $Id: nssinit.c,v 1.62 2003-02-28 21:13:15 ian.mcgreer%sun.com Exp $
*/ */
#include <ctype.h> #include <ctype.h>
@ -397,6 +397,8 @@ nss_FindExternalRoot(const char *dbpath, const char* secmodprefix)
static PRBool nss_IsInitted = PR_FALSE; static PRBool nss_IsInitted = PR_FALSE;
extern SECStatus secoid_Init(void);
static SECStatus static SECStatus
nss_Init(const char *configdir, const char *certPrefix, const char *keyPrefix, nss_Init(const char *configdir, const char *certPrefix, const char *keyPrefix,
const char *secmodName, PRBool readOnly, PRBool noCertDB, const char *secmodName, PRBool readOnly, PRBool noCertDB,
@ -466,6 +468,9 @@ loser:
} }
if (rv == SECSuccess) { if (rv == SECSuccess) {
if (secoid_Init() != SECSuccess) {
return SECFailure;
}
if (STAN_LoadDefaultNSS3TrustDomain() != PR_SUCCESS) { if (STAN_LoadDefaultNSS3TrustDomain() != PR_SUCCESS) {
return SECFailure; return SECFailure;
} }

Просмотреть файл

@ -2674,6 +2674,7 @@ pk11_closePeer(PRBool isFIPS)
} }
static PRBool nsc_init = PR_FALSE; static PRBool nsc_init = PR_FALSE;
extern SECStatus secoid_Init(void);
/* NSC_Initialize initializes the Cryptoki library. */ /* NSC_Initialize initializes the Cryptoki library. */
CK_RV nsc_CommonInitialize(CK_VOID_PTR pReserved, PRBool isFIPS) CK_RV nsc_CommonInitialize(CK_VOID_PTR pReserved, PRBool isFIPS)
@ -2694,6 +2695,12 @@ CK_RV nsc_CommonInitialize(CK_VOID_PTR pReserved, PRBool isFIPS)
} }
} }
rv = secoid_Init();
if (rv != SECSuccess) {
crv = CKR_DEVICE_ERROR;
return crv;
}
rv = RNG_RNGInit(); /* initialize random number generator */ rv = RNG_RNGInit(); /* initialize random number generator */
if (rv != SECSuccess) { if (rv != SECSuccess) {
crv = CKR_DEVICE_ERROR; crv = CKR_DEVICE_ERROR;
@ -2758,6 +2765,8 @@ CK_RV NSC_Initialize(CK_VOID_PTR pReserved)
return crv; return crv;
} }
extern SECStatus SECOID_Shutdown(void);
/* NSC_Finalize indicates that an application is done with the /* NSC_Finalize indicates that an application is done with the
* Cryptoki library.*/ * Cryptoki library.*/
CK_RV nsc_CommonFinalize (CK_VOID_PTR pReserved, PRBool isFIPS) CK_RV nsc_CommonFinalize (CK_VOID_PTR pReserved, PRBool isFIPS)
@ -2792,6 +2801,8 @@ CK_RV nsc_CommonFinalize (CK_VOID_PTR pReserved, PRBool isFIPS)
pk11_CleanupFreeLists(); pk11_CleanupFreeLists();
/* tell freeBL to clean up after itself */ /* tell freeBL to clean up after itself */
BL_Cleanup(); BL_Cleanup();
/* clean up the default OID table */
SECOID_Shutdown();
nsc_init = PR_FALSE; nsc_init = PR_FALSE;
return CKR_OK; return CKR_OK;

Просмотреть файл

@ -1336,12 +1336,16 @@ secoid_HashNumber(const void *key)
} }
static SECStatus SECStatus
InitOIDHash(void) secoid_Init(void)
{ {
PLHashEntry *entry; PLHashEntry *entry;
const SECOidData *oid; const SECOidData *oid;
int i; int i;
if (oidhash) {
return PR_SUCCESS;
}
oidhash = PL_NewHashTable(0, SECITEM_Hash, SECITEM_HashCompare, oidhash = PL_NewHashTable(0, SECITEM_Hash, SECITEM_HashCompare,
PL_CompareValues, NULL, NULL); PL_CompareValues, NULL, NULL);
@ -1388,13 +1392,8 @@ SECOID_FindOIDByMechanism(unsigned long mechanism)
SECOidData *ret; SECOidData *ret;
int rv; int rv;
if ( !oidhash ) { PR_ASSERT(oidhash != NULL);
rv = InitOIDHash();
if ( rv != SECSuccess ) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return NULL;
}
}
ret = PL_HashTableLookupConst ( oidmechhash, (void *)mechanism); ret = PL_HashTableLookupConst ( oidmechhash, (void *)mechanism);
if ( ret == NULL ) { if ( ret == NULL ) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
@ -1409,13 +1408,7 @@ SECOID_FindOID(SECItem *oid)
SECOidData *ret; SECOidData *ret;
int rv; int rv;
if ( !oidhash ) { PR_ASSERT(oidhash != NULL);
rv = InitOIDHash();
if ( rv != SECSuccess ) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return NULL;
}
}
ret = PL_HashTableLookupConst ( oidhash, oid ); ret = PL_HashTableLookupConst ( oidhash, oid );
if ( ret == NULL ) { if ( ret == NULL ) {