Skip to content

Commit 0637be0

Browse files
committed
card-openpgp.c - avoid a memory leak
1 parent 2acc176 commit 0637be0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libopensc/card-openpgp.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ pgp_get_pubkey_pem(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
17471747
/* PKCS#11 3.0: 2.3.5 Edwards EC public keys only support the use
17481748
* of the curveName selection to specify a curve name as defined
17491749
* in [RFC 8032] */
1750-
r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, &p15pubkey, &data, &len);
1750+
r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, &p15pubkey, &data, &len);
17511751
break;
17521752
case SC_OPENPGP_KEYALGO_ECDH:
17531753
/* This yields either EC(DSA) key or EC_MONTGOMERY (curve25519) key */
@@ -2915,6 +2915,12 @@ pgp_update_pubkey_blob(sc_card_t *card, sc_cardctl_openpgp_key_gen_store_info_t
29152915
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
29162916

29172917
r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, &p15pubkey, &data, &len);
2918+
/*
2919+
* key_info is missing an algo_id. sc_pkcs15_encode_pubkey_as_spki
2920+
* allocates one. Free it here.
2921+
*/
2922+
free(p15pubkey.alg_id);
2923+
p15pubkey.alg_id = NULL;
29182924
LOG_TEST_RET(card->ctx, r, "Cannot encode pubkey");
29192925

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

0 commit comments

Comments
 (0)