Skip to content

Commit

Permalink
libckteec: Fix return value for wrong size CK_ULONG
Browse files Browse the repository at this point in the history
We should return CKR_ATTRIBUTE_VALUE_INVALID to indicate that value is
incorrect.

CKR_ATTRIBUTE_TYPE_INVALID is used to indicate that unknown attribute was
provided.

Specified in:
PKCS #11 Cryptographic Token Interface Base Specification
Version 2.40 Plus Errata 01
4.1.1 Creating objects

"2. If the supplied template specifies an invalid value for a valid
attribute, then the attempt should fail with the error code
CKR_ATTRIBUTE_VALUE_INVALID."

Signed-off-by: Vesa Jääskeläinen <vesa.jaaskelainen@vaisala.com>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
  • Loading branch information
vesajaaskelainen authored and jforissier committed Oct 4, 2021
1 parent 96f9ebe commit 1828743
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libckteec/src/serialize_ck.c
Expand Up @@ -195,7 +195,7 @@ static CK_RV serialize_ck_attribute(struct serializer *obj, CK_ATTRIBUTE *attr)
CK_ULONG ck_ulong = 0;

if (attr->ulValueLen < sizeof(CK_ULONG))
return CKR_ATTRIBUTE_TYPE_INVALID;
return CKR_ATTRIBUTE_VALUE_INVALID;

memcpy(&ck_ulong, attr->pValue, sizeof(ck_ulong));
pkcs11_data32 = ck_ulong;
Expand Down Expand Up @@ -297,7 +297,7 @@ static CK_RV deserialize_ck_attribute(struct pkcs11_attribute_head *in,
/* Specific ulong encoded as 32bit in PKCS11 TA API */
if (ck_attr_is_ulong(out->type)) {
if (out->ulValueLen < sizeof(CK_ULONG))
return CKR_ATTRIBUTE_TYPE_INVALID;
return CKR_ATTRIBUTE_VALUE_INVALID;

memcpy(&pkcs11_data32, data, sizeof(uint32_t));
if (out->type == CKA_KEY_GEN_MECHANISM &&
Expand Down

0 comments on commit 1828743

Please sign in to comment.