Skip to content

Commit cf9ac1e

Browse files
committed
Fix C_CopyObject alloc for ECC keys
1 parent 815123c commit cf9ac1e

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/crypto.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,9 @@ CK_RV C_CopyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
12011201

12021202
/* Set the object class from the original object */
12031203
ret = WP11_Object_SetClass(newObj, WP11_Object_GetClass(obj));
1204+
if (ret != 0)
1205+
return CKR_FUNCTION_FAILED;
1206+
ret = WP11_Object_SetType(newObj, WP11_Object_GetType(obj));
12041207
if (ret != 0)
12051208
return CKR_FUNCTION_FAILED;
12061209

src/internal.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7939,6 +7939,24 @@ int WP11_Object_SetClass(WP11_Object* object, CK_OBJECT_CLASS objClass)
79397939
return 0;
79407940
}
79417941

7942+
/**
7943+
* Set the object's type.
7944+
*
7945+
* @param object [in] Object object.
7946+
* @param objType [in] Object's type.
7947+
* @return 0 on success.
7948+
*/
7949+
int WP11_Object_SetType(WP11_Object* object, CK_KEY_TYPE objType)
7950+
{
7951+
if (object->onToken)
7952+
WP11_Lock_LockRW(object->lock);
7953+
object->type = objType;
7954+
if (object->onToken)
7955+
WP11_Lock_UnlockRW(object->lock);
7956+
7957+
return 0;
7958+
}
7959+
79427960
/**
79437961
* Find an object based on the handle.
79447962
*

wolfpkcs11/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ WP11_LOCAL int WP11_Object_DataObject(WP11_Object* object, unsigned char** data,
401401
CK_ULONG* len);
402402

403403
WP11_LOCAL int WP11_Object_SetClass(WP11_Object* object, CK_OBJECT_CLASS objClass);
404+
WP11_LOCAL int WP11_Object_SetType(WP11_Object* object, CK_KEY_TYPE objType);
404405
WP11_LOCAL CK_OBJECT_CLASS WP11_Object_GetClass(WP11_Object* object);
405406

406407
#ifdef WOLFPKCS11_NSS

0 commit comments

Comments
 (0)