Skip to content

Commit

Permalink
framework-pkcs15.c - fix memory leak
Browse files Browse the repository at this point in the history
 On branch X25519-improvements-2
 Changes to be committed:
	modified:   pkcs11/framework-pkcs15.c
  • Loading branch information
dengert committed Sep 6, 2024
1 parent 56b7ad6 commit dd34af2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/pkcs11/framework-pkcs15.c
Original file line number Diff line number Diff line change
Expand Up @@ -2814,11 +2814,18 @@ pkcs15_create_public_key(struct sc_pkcs11_slot *slot, struct sc_profile *profile
case CKA_EC_POINT:
switch (key_type) {
case CKK_EC:
if (sc_pkcs15_decode_pubkey_ec(p11card->card->ctx, ec, attr->pValue, attr->ulValueLen) < 0)
if (sc_pkcs15_decode_pubkey_ec(p11card->card->ctx, ec, attr->pValue, attr->ulValueLen) < 0) {
free(ec->ecpointQ.value);
ec->ecpointQ.value = NULL;
ec->ecpointQ.len = 0;
sc_clear_ec_params(&ec->params);
return CKR_ATTRIBUTE_VALUE_INVALID;
}

break;
case CKK_EC_EDWARDS:
case CKK_EC_MONTGOMERY:
/* TODO my need to decode here too to support OS vs BS */
/* Difference between 25519 and 448 versions set by ec->ecpointQ.len below */
ec->ecpointQ.value = calloc(1, attr->ulValueLen);
ec->ecpointQ.len = attr->ulValueLen;
Expand Down Expand Up @@ -2891,6 +2898,7 @@ pkcs15_create_public_key(struct sc_pkcs11_slot *slot, struct sc_profile *profile
key_type == CKK_EC_EDWARDS ||
key_type == CKK_EC_MONTGOMERY) {
sc_clear_ec_params(&ec->params);
free(ec->ecpointQ.value);
}
if (rc < 0)
return sc_to_cryptoki_error(rc, "C_CreateObject");
Expand Down

0 comments on commit dd34af2

Please sign in to comment.