Bug 469601: Coverity errors reported for pk11wrap
authornelson%bolyard.com
Mon, 15 Mar 2010 06:38:09 +0000
changeset 9580 efae67e2b4984c7335f51c217a5e1c9961715c56
parent 9578 9dcfb8283a581e4d4083f24a70315f30cdc3b967
child 9582 6e185b99bc3044863c4ecd0d804a525aec694c99
push idunknown
push userunknown
push dateunknown
bugs469601
Bug 469601: Coverity errors reported for pk11wrap Patch contributed by Shailendra Jain <shailen.n.jain@gmail.com>, r=nelson
security/nss/lib/pk11wrap/pk11cert.c
security/nss/lib/pk11wrap/pk11skey.c
--- a/security/nss/lib/pk11wrap/pk11cert.c
+++ b/security/nss/lib/pk11wrap/pk11cert.c
@@ -2472,28 +2472,35 @@ PK11_ListCertsInSlot(PK11SlotInfo *slot)
     }
 
     return certs;
 }
 
 PK11SlotList *
 PK11_GetAllSlotsForCert(CERTCertificate *cert, void *arg)
 {
-    NSSCertificate *c = STAN_GetNSSCertificate(cert);
-    /* add multiple instances to the cert list */
     nssCryptokiObject **ip;
-    nssCryptokiObject **instances = nssPKIObject_GetInstances(&c->object);
     PK11SlotList *slotList;
+    NSSCertificate *c;
+    nssCryptokiObject **instances;
     PRBool found = PR_FALSE;
 
     if (!cert) {
 	PORT_SetError(SEC_ERROR_INVALID_ARGS);
 	return NULL;
     }
 
+    c = STAN_GetNSSCertificate(cert);
+    if (!c) {
+	CERT_MapStanError();
+	return NULL;
+    }
+
+    /* add multiple instances to the cert list */
+    instances = nssPKIObject_GetInstances(&c->object);
     if (!instances) {
 	PORT_SetError(SEC_ERROR_NO_TOKEN);
 	return NULL;
     }
 
     slotList = PK11_NewSlotList();
     if (!slotList) {
 	nssCryptokiObjectArray_Destroy(instances);
--- a/security/nss/lib/pk11wrap/pk11skey.c
+++ b/security/nss/lib/pk11wrap/pk11skey.c
@@ -1149,23 +1149,28 @@ PK11_PubWrapSymKey(CK_MECHANISM_TYPE typ
     CK_ULONG len =  wrappedKey->len;
     PK11SymKey *newKey = NULL;
     CK_OBJECT_HANDLE id;
     CK_MECHANISM mechanism;
     PRBool owner = PR_TRUE;
     CK_SESSION_HANDLE session;
     CK_RV crv;
 
+    if (symKey == NULL) {
+	PORT_SetError( SEC_ERROR_INVALID_ARGS );
+	return SECFailure;
+    }
+
     /* if this slot doesn't support the mechanism, go to a slot that does */
     newKey = pk11_ForceSlot(symKey,type,CKA_ENCRYPT);
     if (newKey != NULL) {
 	symKey = newKey;
     }
 
-    if ((symKey == NULL) || (symKey->slot == NULL)) {
+    if (symKey->slot == NULL) {
 	PORT_SetError( SEC_ERROR_NO_MODULE );
 	return SECFailure;
     }
 
     slot = symKey->slot;
     mechanism.mechanism = pk11_mapWrapKeyType(pubKey->keyType);
     mechanism.pParameter = NULL;
     mechanism.ulParameterLen = 0;