overwrite old entry during import, so that changing trust works correctly
authorian.mcgreer%sun.com
Mon, 22 Apr 2002 15:21:06 +0000
changeset 3028 8b4ed8bce8689605f285e05e5260ef92c54041f1
parent 3027 f3556c983228bfc2318e933197b1b00e71e20560
child 3030 77bf4d5fbd974a36dac2e2d67600158a37f0a5aa
push idunknown
push userunknown
push dateunknown
overwrite old entry during import, so that changing trust works correctly
security/nss/lib/dev/devutil.c
--- a/security/nss/lib/dev/devutil.c
+++ b/security/nss/lib/dev/devutil.c
@@ -1263,39 +1263,55 @@ nssTokenObjectCache_ImportObject
   CK_ATTRIBUTE_PTR ot,
   CK_ULONG otlen
 )
 {
     PRStatus status = PR_SUCCESS;
     PRUint32 count;
     nssCryptokiObjectAndAttributes **oa, ***otype;
     PRUint32 objectType;
+    PRBool haveIt = PR_FALSE;
     PZ_Lock(cache->lock);
     switch (objclass) {
     case CKO_CERTIFICATE:    objectType = cachedCerts; break;
     case CKO_NETSCAPE_TRUST: objectType = cachedTrust; break;
     case CKO_NETSCAPE_CRL:   objectType = cachedCRLs;  break;
     default:
 	PZ_Unlock(cache->lock);
 	return PR_SUCCESS; /* don't need to import it here */
     }
     if (!cache_available_for_object_type(cache, objectType)) {
 	PZ_Unlock(cache->lock);
 	return PR_SUCCESS; /* cache not active, ignored */
     }
     count = 0;
     otype = &cache->objects[objectType]; /* index into array of types */
     oa = *otype; /* the array of objects for this type */
-    while (oa && *oa++) count++;
-    if (count > 0) {
-	*otype = nss_ZREALLOCARRAY(*otype,
-	                           nssCryptokiObjectAndAttributes *, 
-	                           count + 2);
+    while (oa && *oa) {
+	if (nssCryptokiObject_Equal((*oa)->object, object)) {
+	    haveIt = PR_TRUE;
+	    break;
+	}
+	count++;
+	oa++;
+    }
+    if (haveIt) {
+	/* Destroy the old entry */
+	(*oa)->object->token = NULL;
+	nssCryptokiObject_Destroy((*oa)->object);
+	nssArena_Destroy((*oa)->arena);
     } else {
-	*otype = nss_ZNEWARRAY(NULL, nssCryptokiObjectAndAttributes *, 2);
+	/* Create space for a new entry */
+	if (count > 0) {
+	    *otype = nss_ZREALLOCARRAY(*otype,
+	                               nssCryptokiObjectAndAttributes *, 
+	                               count + 2);
+	} else {
+	    *otype = nss_ZNEWARRAY(NULL, nssCryptokiObjectAndAttributes *, 2);
+	}
     }
     if (*otype) {
 	nssCryptokiObject *copyObject = nssCryptokiObject_Clone(object);
 	(*otype)[count] = make_object_and_attr(copyObject, ot, otlen);
 	status = ((*otype)[count] != NULL) ? PR_SUCCESS : PR_FAILURE;
     } else {
 	status = PR_FAILURE;
     }