diff options
Diffstat (limited to 'ckcapi-object.c')
| -rw-r--r-- | ckcapi-object.c | 23 | 
1 files changed, 16 insertions, 7 deletions
| diff --git a/ckcapi-object.c b/ckcapi-object.c index c620cc4..da3a467 100644 --- a/ckcapi-object.c +++ b/ckcapi-object.c @@ -32,7 +32,7 @@ ckcapi_object_clear_all(void)  		if(object_array)  		{ -			for(i = 0; i < object_array->len; ++i) +			for(i = 1; i < object_array->len; ++i)  			{  				ASSERT(ckcapi_array_index(object_array, CkCapiObject*, i));  				object_free(ckcapi_array_index(object_array, CkCapiObject*, i)); @@ -70,13 +70,15 @@ ckcapi_object_register(CkCapiSession* sess, CkCapiObject* obj)  {  	CkCapiObject* prev;  	CK_RV ret = CKR_OK; +	void* key; +	size_t klen;  	ASSERT(sess);  	ASSERT(obj->id == 0);  	ASSERT(obj->unique_key); -	ASSERT(obj->unique_len); +	ASSERT(obj->unique_len > 0); -	DBGS(sess, "registering new object"); +	DBG(("registering object"));  	ckcapi_lock_global(); @@ -105,14 +107,21 @@ ckcapi_object_register(CkCapiSession* sess, CkCapiObject* obj)  			ASSERT(object_array);  			ASSERT(object_hash); +			/* The type of object is part of the hash */ +			key = obj->unique_key; +			klen = obj->unique_len; + +			/* Sanity check, in case calcs went wrong somewhere */ +			ASSERT(klen < 0xFFFFFF); +  			/* Look in the hash and find a previous object */ -			prev = ckcapi_hash_get(object_hash, obj->unique_key, obj->unique_len); +			prev = ckcapi_hash_get(object_hash, key, klen);  			if(prev)  			{  				/* Register it in the previous object's place */  				obj->id = prev->id;  				ASSERT(prev->id < object_array->len); -				if(ckcapi_hash_set(object_hash, obj->unique_key, obj->unique_len, obj)) +				if(ckcapi_hash_set(object_hash, key, klen, obj))  				{  					ckcapi_array_index(object_array, CkCapiObject*, obj->id) = obj;  					object_free(prev); @@ -129,7 +138,7 @@ ckcapi_object_register(CkCapiSession* sess, CkCapiObject* obj)  				/* Register it at the end of the array */  				obj->id = object_array->len;  				ASSERT(obj->id > 0); -				if(ckcapi_hash_set(object_hash, obj->unique_key, obj->unique_len, obj)) +				if(ckcapi_hash_set(object_hash, key, klen, obj))  				{  					if(ckcapi_array_append(object_array, obj))  					{ @@ -140,7 +149,7 @@ ckcapi_object_register(CkCapiSession* sess, CkCapiObject* obj)  						ret = CKR_HOST_MEMORY;  						/* Roll back our addition */ -						ckcapi_hash_rem(object_hash, obj->unique_key, obj->unique_len); +						ckcapi_hash_rem(object_hash, key, klen);  					}  				}  				else | 
