Skip to content

Commit a0875ca

Browse files
committed
Fixes for attempted Data and KeyID allocations of zero length
1 parent 8d3e610 commit a0875ca

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/crypto.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,9 @@ static CK_RV SetAttributeValue(WP11_Session* session, WP11_Object* obj,
660660
}
661661
ret = WP11_Object_SetAttr(obj, attr->type, (byte*)attr->pValue,
662662
attr->ulValueLen);
663-
if (ret == BAD_FUNC_ARG)
663+
if (ret == MEMORY_E)
664+
return CKR_DEVICE_MEMORY;
665+
else if (ret == BAD_FUNC_ARG)
664666
return CKR_ATTRIBUTE_VALUE_INVALID;
665667
else if (ret == BUFFER_E)
666668
return CKR_BUFFER_TOO_SMALL;

src/internal.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8320,10 +8320,12 @@ static int WP11_Object_SetKeyId(WP11_Object* object, unsigned char* keyId,
83208320

83218321
if (object->keyId != NULL)
83228322
XFREE(object->keyId, NULL, DYNAMIC_TYPE_TMP_BUFFER);
8323-
object->keyId = (unsigned char*)XMALLOC(keyIdLen, NULL,
8324-
DYNAMIC_TYPE_TMP_BUFFER);
8325-
if (object->keyId == NULL)
8326-
ret = MEMORY_E;
8323+
if (keyIdLen > 0) {
8324+
object->keyId = (unsigned char*)XMALLOC(keyIdLen, NULL,
8325+
DYNAMIC_TYPE_TMP_BUFFER);
8326+
if (object->keyId == NULL)
8327+
ret = MEMORY_E;
8328+
}
83278329
if (ret == 0) {
83288330
XMEMCPY(object->keyId, keyId, keyIdLen);
83298331
object->keyIdLen = keyIdLen;
@@ -8349,10 +8351,12 @@ static int WP11_Object_SetData(byte** attribute, int* attributeLen, byte* data,
83498351

83508352
if (*attribute != NULL)
83518353
XFREE(*attribute, NULL, DYNAMIC_TYPE_TMP_BUFFER);
8352-
*attribute = (byte*)XMALLOC(dataLen, NULL,
8353-
DYNAMIC_TYPE_TMP_BUFFER);
8354-
if (*attribute == NULL)
8355-
ret = MEMORY_E;
8354+
if (dataLen > 0) {
8355+
*attribute = (byte*)XMALLOC(dataLen, NULL,
8356+
DYNAMIC_TYPE_TMP_BUFFER);
8357+
if (*attribute == NULL)
8358+
ret = MEMORY_E;
8359+
}
83568360
if (ret == 0) {
83578361
XMEMCPY(*attribute, data, dataLen);
83588362
*attributeLen = dataLen;
@@ -8571,7 +8575,7 @@ int WP11_Object_SetAttr(WP11_Object* object, CK_ATTRIBUTE_TYPE type, byte* data,
85718575
case CKK_HKDF:
85728576
#endif
85738577
case CKK_GENERIC_SECRET:
8574-
break;
8578+
break;
85758579
default:
85768580
ret = BAD_FUNC_ARG;
85778581
break;

0 commit comments

Comments
 (0)