Skip to content

Commit

Permalink
pkcs15init/pkcs15-openpgp.c - avoid a double free
Browse files Browse the repository at this point in the history
Avoid a double free When PKCS11 tries to write a pubkey
as second part to write a key.

 On branch X25519-improvements-2
 Changes to be committed:
	modified:   pkcs15init/pkcs15-openpgp.c
  • Loading branch information
dengert committed Nov 30, 2024
1 parent 4e1fc5a commit 4e8070b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/pkcs15init/pkcs15-openpgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ static int openpgp_store_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
break;

/* Unlike RSA which includes modulus in privkey,
* PKCS11 stores pubkey as separate operation
* and pkcs15_init includes public ecpoint with private key,
* PKCS11 stores pubkey as separate operation and
* we only get here if called from openpgp_store_data
* after the private key was stored as first operation.
*/
case SC_PKCS15_TYPE_PUBKEY_EC:
case SC_PKCS15_TYPE_PUBKEY_EDDSA:
Expand Down Expand Up @@ -271,7 +274,7 @@ static int openpgp_store_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,

r = sc_card_ctl(card, SC_CARDCTL_OPENPGP_STORE_KEY, &key_info);

free(key_info.u.ec.ecpointQ);
/* do not free key_info.u.ec.ecpointQ. openpgp_store_data will free it */
break;

default:
Expand Down

0 comments on commit 4e8070b

Please sign in to comment.