authentic: fixed resource leak
pkcs15-authentic: fixed resource leak card-authentic: fixed resource leak
This commit is contained in:
parent
e215b7b4fb
commit
4af4308d19
|
@ -2302,13 +2302,19 @@ authentic_sm_get_wrapped_apdu(struct sc_card *card, struct sc_apdu *plain, struc
|
||||||
memcpy((unsigned char *) apdu->data, plain->data, plain->datalen);
|
memcpy((unsigned char *) apdu->data, plain->data, plain->datalen);
|
||||||
|
|
||||||
apdu->resp = calloc (1, plain->resplen + 32);
|
apdu->resp = calloc (1, plain->resplen + 32);
|
||||||
if (!apdu->resp)
|
if (!apdu->resp) {
|
||||||
|
free(apdu);
|
||||||
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
|
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
card->sm_ctx.info.cmd = SM_CMD_APDU_TRANSMIT;
|
card->sm_ctx.info.cmd = SM_CMD_APDU_TRANSMIT;
|
||||||
card->sm_ctx.info.cmd_data = (void *)apdu;
|
card->sm_ctx.info.cmd_data = (void *)apdu;
|
||||||
|
|
||||||
rv = card->sm_ctx.module.ops.get_apdus(ctx, &card->sm_ctx.info, NULL, 0, NULL);
|
rv = card->sm_ctx.module.ops.get_apdus(ctx, &card->sm_ctx.info, NULL, 0, NULL);
|
||||||
|
if (rv < 0) {
|
||||||
|
free(apdu->resp);
|
||||||
|
free(apdu);
|
||||||
|
}
|
||||||
LOG_TEST_RET(ctx, rv, "SM: GET_APDUS failed");
|
LOG_TEST_RET(ctx, rv, "SM: GET_APDUS failed");
|
||||||
|
|
||||||
*sm_apdu = apdu;
|
*sm_apdu = apdu;
|
||||||
|
|
|
@ -352,6 +352,7 @@ authentic_sdo_allocate_prvkey(struct sc_profile *profile, struct sc_card *card,
|
||||||
sdo = calloc(1, sizeof(struct sc_authentic_sdo));
|
sdo = calloc(1, sizeof(struct sc_authentic_sdo));
|
||||||
if (!sdo)
|
if (!sdo)
|
||||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot allocate 'sc_authentic_sdo'");
|
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot allocate 'sc_authentic_sdo'");
|
||||||
|
*out = sdo;
|
||||||
|
|
||||||
sdo->magic = AUTHENTIC_SDO_MAGIC;
|
sdo->magic = AUTHENTIC_SDO_MAGIC;
|
||||||
sdo->docp.id = key_info->key_reference & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL;
|
sdo->docp.id = key_info->key_reference & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL;
|
||||||
|
@ -359,13 +360,11 @@ authentic_sdo_allocate_prvkey(struct sc_profile *profile, struct sc_card *card,
|
||||||
|
|
||||||
rv = authentic_docp_set_acls(card, file, authentic_v3_rsa_ac_ops,
|
rv = authentic_docp_set_acls(card, file, authentic_v3_rsa_ac_ops,
|
||||||
sizeof(authentic_v3_rsa_ac_ops)/sizeof(authentic_v3_rsa_ac_ops[0]), &sdo->docp);
|
sizeof(authentic_v3_rsa_ac_ops)/sizeof(authentic_v3_rsa_ac_ops[0]), &sdo->docp);
|
||||||
LOG_TEST_RET(ctx, rv, "Cannot set key ACLs from file");
|
|
||||||
|
|
||||||
sc_file_free(file);
|
sc_file_free(file);
|
||||||
|
LOG_TEST_RET(ctx, rv, "Cannot set key ACLs from file");
|
||||||
|
|
||||||
sc_log(ctx, "sdo(mech:%X,id:%X,acls:%s)", sdo->docp.mech, sdo->docp.id,
|
sc_log(ctx, "sdo(mech:%X,id:%X,acls:%s)", sdo->docp.mech, sdo->docp.id,
|
||||||
sc_dump_hex(sdo->docp.acl_data, sdo->docp.acl_data_len));
|
sc_dump_hex(sdo->docp.acl_data, sdo->docp.acl_data_len));
|
||||||
*out = sdo;
|
|
||||||
|
|
||||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -719,12 +718,12 @@ authentic_pkcs15_delete_rsa_sdo (struct sc_profile *profile, struct sc_pkcs15_ca
|
||||||
sc_log(ctx, "delete SDO RSA key (ref:%i,size:%i)", key_info->key_reference, key_info->modulus_length);
|
sc_log(ctx, "delete SDO RSA key (ref:%i,size:%i)", key_info->key_reference, key_info->modulus_length);
|
||||||
|
|
||||||
rv = authentic_pkcs15_new_file(profile, p15card->card, SC_PKCS15_TYPE_PRKEY_RSA, key_info->key_reference, &file);
|
rv = authentic_pkcs15_new_file(profile, p15card->card, SC_PKCS15_TYPE_PRKEY_RSA, key_info->key_reference, &file);
|
||||||
LOG_TEST_RET(ctx, rv, "PRKEY_RSA instantiation file error");
|
LOG_TEST_GOTO_ERR(ctx, rv, "PRKEY_RSA instantiation file error");
|
||||||
|
|
||||||
p15card->card->caps &= ~SC_CARD_CAP_USE_FCI_AC;
|
p15card->card->caps &= ~SC_CARD_CAP_USE_FCI_AC;
|
||||||
rv = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_DELETE);
|
rv = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_DELETE);
|
||||||
p15card->card->caps = caps;
|
p15card->card->caps = caps;
|
||||||
LOG_TEST_RET(ctx, rv, "'DELETE' authentication failed for parent RSA key");
|
LOG_TEST_GOTO_ERR(ctx, rv, "'DELETE' authentication failed for parent RSA key");
|
||||||
|
|
||||||
sdo.magic = AUTHENTIC_SDO_MAGIC;
|
sdo.magic = AUTHENTIC_SDO_MAGIC;
|
||||||
sdo.docp.id = key_info->key_reference & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL;
|
sdo.docp.id = key_info->key_reference & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL;
|
||||||
|
@ -733,8 +732,11 @@ authentic_pkcs15_delete_rsa_sdo (struct sc_profile *profile, struct sc_pkcs15_ca
|
||||||
rv = sc_card_ctl(p15card->card, SC_CARDCTL_AUTHENTIC_SDO_DELETE, &sdo);
|
rv = sc_card_ctl(p15card->card, SC_CARDCTL_AUTHENTIC_SDO_DELETE, &sdo);
|
||||||
if (rv == SC_ERROR_DATA_OBJECT_NOT_FOUND)
|
if (rv == SC_ERROR_DATA_OBJECT_NOT_FOUND)
|
||||||
rv = SC_SUCCESS;
|
rv = SC_SUCCESS;
|
||||||
LOG_TEST_RET(ctx, rv, "SC_CARDCTL_AUTHENTIC_SDO_DELETE failed for private key");
|
LOG_TEST_GOTO_ERR(ctx, rv, "SC_CARDCTL_AUTHENTIC_SDO_DELETE failed for private key");
|
||||||
|
|
||||||
|
err:
|
||||||
|
if (file)
|
||||||
|
sc_file_free(file);
|
||||||
LOG_FUNC_RETURN(ctx, rv);
|
LOG_FUNC_RETURN(ctx, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue