changeset 4161:ca2dbbf9df8a

6483107 softtoken C_GenerateKeypair dumps core in multi-threaded apps
author mcpowers
date Thu, 03 May 2007 15:46:11 -0700
parents c23579e36e7c
children 4bfd590bb99a
files usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystore.c usr/src/lib/pkcs11/pkcs11_softtoken/common/softObjectUtil.c
diffstat 2 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystore.c	Thu May 03 15:11:37 2007 -0700
+++ b/usr/src/lib/pkcs11/pkcs11_softtoken/common/softKeystore.c	Thu May 03 15:46:11 2007 -0700
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -1814,19 +1814,23 @@
 	if (rv != CKR_OK)
 		return (rv);
 
+	(void) pthread_mutex_lock(&soft_slot.slot_mutex);
 	if (objp->object_type == TOKEN_PUBLIC) {
 		if ((soft_keystore_put_new_obj(buf, len, B_TRUE,
 		    B_FALSE, &objp->ks_handle)) == -1) {
+			(void) pthread_mutex_unlock(&soft_slot.slot_mutex);
 			free(buf);
 			return (CKR_FUNCTION_FAILED);
 		}
 	} else {
 		if ((soft_keystore_put_new_obj(buf, len, B_FALSE,
 		    B_FALSE, &objp->ks_handle)) == -1) {
+			(void) pthread_mutex_unlock(&soft_slot.slot_mutex);
 			free(buf);
 			return (CKR_FUNCTION_FAILED);
 		}
 	}
+	(void) pthread_mutex_unlock(&soft_slot.slot_mutex);
 	free(buf);
 	return (CKR_OK);
 
--- a/usr/src/lib/pkcs11/pkcs11_softtoken/common/softObjectUtil.c	Thu May 03 15:11:37 2007 -0700
+++ b/usr/src/lib/pkcs11/pkcs11_softtoken/common/softObjectUtil.c	Thu May 03 15:46:11 2007 -0700
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -871,12 +871,16 @@
     boolean_t lock_held)
 {
 
+	if (!lock_held)
+		(void) pthread_mutex_lock(&soft_slot.slot_mutex);
 	if (persistent)
 		/* Delete the object from the keystore. */
 		(void) soft_keystore_del_obj(&objp->ks_handle, B_FALSE);
 
 	/* Remove the object from the slot's token object list. */
-	soft_remove_token_object_from_slot(objp, lock_held);
+	soft_remove_token_object_from_slot(objp, B_TRUE);
+	if (!lock_held)
+		(void) pthread_mutex_unlock(&soft_slot.slot_mutex);
 
 	soft_delete_object_cleanup(objp);
 }
@@ -1341,6 +1345,12 @@
 		ondisk_obj = on_disk_list;
 		prev_ondisk_obj = NULL;
 
+		/* larval object that has not been written to disk */
+		if (in_core_obj->ks_handle.name[0] == '\0') {
+			in_core_obj = in_core_obj->next;
+			continue;
+		}
+
 		while ((!found) && (ondisk_obj != NULL)) {
 
 			if (strcmp((char *)((ondisk_obj->ks_handle).name),