Skip to content

Commit

Permalink
card-openpgp.c - avoid a memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
dengert committed Dec 14, 2024
1 parent 2acc176 commit 0637be0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/libopensc/card-openpgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ pgp_get_pubkey_pem(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
/* PKCS#11 3.0: 2.3.5 Edwards EC public keys only support the use
* of the curveName selection to specify a curve name as defined
* in [RFC 8032] */
r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, &p15pubkey, &data, &len);
r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, &p15pubkey, &data, &len);
break;
case SC_OPENPGP_KEYALGO_ECDH:
/* This yields either EC(DSA) key or EC_MONTGOMERY (curve25519) key */
Expand Down Expand Up @@ -2915,6 +2915,12 @@ pgp_update_pubkey_blob(sc_card_t *card, sc_cardctl_openpgp_key_gen_store_info_t
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);

r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, &p15pubkey, &data, &len);
/*
* key_info is missing an algo_id. sc_pkcs15_encode_pubkey_as_spki
* allocates one. Free it here.
*/
free(p15pubkey.alg_id);
p15pubkey.alg_id = NULL;
LOG_TEST_RET(card->ctx, r, "Cannot encode pubkey");

sc_log(card->ctx, "Updating blob %04X's content.", blob_id);
Expand Down

0 comments on commit 0637be0

Please sign in to comment.