NULL parameter check moved to sc_file_free()
This fixes numerous issues where the check is *not* performed, and also simplifies the code.
This commit is contained in:
parent
2c6dadfb44
commit
645780e6d4
|
@ -565,15 +565,12 @@ authentic_set_current_files(struct sc_card *card, struct sc_path *path,
|
|||
card->cache.current_df->path.len += cur_df_path.len;
|
||||
}
|
||||
|
||||
if (card->cache.current_ef) {
|
||||
sc_file_free(card->cache.current_ef);
|
||||
card->cache.current_ef = NULL;
|
||||
}
|
||||
|
||||
card->cache.valid = 1;
|
||||
}
|
||||
else {
|
||||
if (card->cache.current_ef)
|
||||
sc_file_free(card->cache.current_ef);
|
||||
card->cache.current_ef = NULL;
|
||||
sc_file_dup(&card->cache.current_ef, file);
|
||||
|
@ -625,11 +622,9 @@ authentic_select_mf(struct sc_card *card, struct sc_file **file_out)
|
|||
LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
|
||||
|
||||
if (card->cache.valid == 1) {
|
||||
if (card->cache.current_df)
|
||||
sc_file_free(card->cache.current_df);
|
||||
card->cache.current_df = NULL;
|
||||
|
||||
if (card->cache.current_ef)
|
||||
sc_file_free(card->cache.current_ef);
|
||||
card->cache.current_ef = NULL;
|
||||
}
|
||||
|
@ -1220,7 +1215,7 @@ authentic_delete_file(struct sc_card *card, const struct sc_path *path)
|
|||
}
|
||||
LOG_TEST_RET(ctx, rv, "Delete file failed");
|
||||
|
||||
if (card->cache.valid && card->cache.current_ef) {
|
||||
if (card->cache.valid) {
|
||||
sc_file_free(card->cache.current_ef);
|
||||
card->cache.current_ef = NULL;
|
||||
}
|
||||
|
|
|
@ -556,10 +556,8 @@ static int dnie_get_info(sc_card_t * card, char *data[])
|
|||
|
||||
/* phase 2: get IDESP */
|
||||
sc_format_path("3F000006", &path);
|
||||
if (file) {
|
||||
sc_file_free(file);
|
||||
file = NULL;
|
||||
}
|
||||
if (buffer) {
|
||||
free(buffer);
|
||||
buffer=NULL;
|
||||
|
@ -581,10 +579,8 @@ static int dnie_get_info(sc_card_t * card, char *data[])
|
|||
get_info_ph3:
|
||||
/* phase 3: get DNIe software version */
|
||||
sc_format_path("3F002F03", &path);
|
||||
if (file) {
|
||||
sc_file_free(file);
|
||||
file = NULL;
|
||||
}
|
||||
if (buffer) {
|
||||
free(buffer);
|
||||
buffer=NULL;
|
||||
|
@ -614,10 +610,8 @@ get_info_ph3:
|
|||
msg = NULL;
|
||||
|
||||
get_info_end:
|
||||
if (file) {
|
||||
sc_file_free(file);
|
||||
file = NULL;
|
||||
}
|
||||
if (buffer) {
|
||||
free(buffer);
|
||||
buffer=NULL;
|
||||
|
@ -1206,7 +1200,6 @@ static int dnie_compose_and_send_apdu(sc_card_t *card, const u8 *path, size_t pa
|
|||
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
res = card->ops->process_fci(card, file, apdu.resp + 2, apdu.resp[1]);
|
||||
if (*file_out != NULL)
|
||||
sc_file_free(*file_out);
|
||||
*file_out = file;
|
||||
dnie_free_apdu_buffers(&apdu, rbuf, sizeof(rbuf));
|
||||
|
|
|
@ -498,11 +498,8 @@ static int entersafe_select_fid(sc_card_t *card,
|
|||
path.len=2;
|
||||
|
||||
r = iso_ops->select_file(card,&path,&file);
|
||||
if(r && file)
|
||||
{
|
||||
if(file)
|
||||
if (r)
|
||||
sc_file_free(file);
|
||||
}
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
|
||||
/* update cache */
|
||||
|
@ -520,14 +517,9 @@ static int entersafe_select_fid(sc_card_t *card,
|
|||
}
|
||||
|
||||
if (file_out)
|
||||
{
|
||||
*file_out = file;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(file)
|
||||
sc_file_free(file);
|
||||
}
|
||||
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -288,11 +288,11 @@ iasecc_select_mf(struct sc_card *card, struct sc_file **file_out)
|
|||
mf_file->type = SC_FILE_TYPE_DF;
|
||||
mf_file->path = path;
|
||||
|
||||
if (card->cache.valid && card->cache.current_df)
|
||||
if (card->cache.valid)
|
||||
sc_file_free(card->cache.current_df);
|
||||
card->cache.current_df = NULL;
|
||||
|
||||
if (card->cache.valid && card->cache.current_ef)
|
||||
if (card->cache.valid)
|
||||
sc_file_free(card->cache.current_ef);
|
||||
card->cache.current_ef = NULL;
|
||||
|
||||
|
@ -895,7 +895,7 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path,
|
|||
|
||||
if (file_out)
|
||||
*file_out = file;
|
||||
else if (file)
|
||||
else
|
||||
sc_file_free(file);
|
||||
|
||||
if (lpath.type == SC_PATH_TYPE_DF_NAME)
|
||||
|
@ -915,7 +915,6 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path,
|
|||
&& !memcmp(card->cache.current_df->path.value, lpath.value, lpath.len)) {
|
||||
sc_log(ctx, "returns current DF path %s", sc_print_path(&card->cache.current_df->path));
|
||||
if (file_out) {
|
||||
if (*file_out)
|
||||
sc_file_free(*file_out);
|
||||
sc_file_dup(file_out, card->cache.current_df);
|
||||
}
|
||||
|
@ -1010,7 +1009,7 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path,
|
|||
if (rv == SC_ERROR_FILE_NOT_FOUND && cache_valid && df_from_cache) {
|
||||
card->cache.valid = 0;
|
||||
sc_log(ctx, "iasecc_select_file() file not found, retry without cached DF");
|
||||
if (file_out && *file_out) {
|
||||
if (file_out) {
|
||||
sc_file_free(*file_out);
|
||||
*file_out = NULL;
|
||||
}
|
||||
|
@ -1042,12 +1041,12 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path,
|
|||
|
||||
sc_log(ctx, "FileType %i", file->type);
|
||||
if (file->type == SC_FILE_TYPE_DF) {
|
||||
if (card->cache.valid && card->cache.current_df)
|
||||
if (card->cache.valid)
|
||||
sc_file_free(card->cache.current_df);
|
||||
card->cache.current_df = NULL;
|
||||
|
||||
|
||||
if (card->cache.valid && card->cache.current_ef)
|
||||
if (card->cache.valid)
|
||||
sc_file_free(card->cache.current_ef);
|
||||
card->cache.current_ef = NULL;
|
||||
|
||||
|
@ -1055,7 +1054,7 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path,
|
|||
card->cache.valid = 1;
|
||||
}
|
||||
else {
|
||||
if (card->cache.valid && card->cache.current_ef)
|
||||
if (card->cache.valid)
|
||||
sc_file_free(card->cache.current_ef);
|
||||
|
||||
card->cache.current_ef = NULL;
|
||||
|
@ -1064,7 +1063,6 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path,
|
|||
}
|
||||
|
||||
if (file_out) {
|
||||
if (*file_out)
|
||||
sc_file_free(*file_out);
|
||||
*file_out = file;
|
||||
}
|
||||
|
@ -1073,11 +1071,9 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path,
|
|||
}
|
||||
}
|
||||
else if (lpath.type == SC_PATH_TYPE_DF_NAME) {
|
||||
if (card->cache.current_df)
|
||||
sc_file_free(card->cache.current_df);
|
||||
card->cache.current_df = NULL;
|
||||
|
||||
if (card->cache.current_ef)
|
||||
sc_file_free(card->cache.current_ef);
|
||||
card->cache.current_ef = NULL;
|
||||
|
||||
|
@ -1388,7 +1384,6 @@ iasecc_finish(struct sc_card *card)
|
|||
LOG_FUNC_CALLED(ctx);
|
||||
|
||||
while (se_info) {
|
||||
if (se_info->df)
|
||||
sc_file_free(se_info->df);
|
||||
next = se_info->next;
|
||||
free(se_info);
|
||||
|
@ -1436,7 +1431,7 @@ iasecc_delete_file(struct sc_card *card, const struct sc_path *path)
|
|||
rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
LOG_TEST_RET(ctx, rv, "Delete file failed");
|
||||
|
||||
if (card->cache.valid && card->cache.current_ef)
|
||||
if (card->cache.valid)
|
||||
sc_file_free(card->cache.current_ef);
|
||||
card->cache.current_ef = NULL;
|
||||
}
|
||||
|
@ -1916,7 +1911,6 @@ iasecc_se_at_to_chv_reference(struct sc_card *card, unsigned reference,
|
|||
if (chv_reference)
|
||||
*chv_reference = crt.refs[0];
|
||||
|
||||
if (se.df)
|
||||
sc_file_free(se.df);
|
||||
|
||||
LOG_FUNC_RETURN(ctx, rv);
|
||||
|
@ -2211,7 +2205,6 @@ iasecc_pin_get_policy (struct sc_card *card, struct sc_pin_cmd_data *data)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (se.df)
|
||||
sc_file_free(se.df);
|
||||
}
|
||||
|
||||
|
@ -2977,7 +2970,6 @@ iasecc_get_chv_reference_from_se(struct sc_card *card, int *se_reference)
|
|||
rv = iasecc_se_get_crt(card, &se, &crt);
|
||||
LOG_TEST_RET(ctx, rv, "Cannot get 'USER PASSWORD' authentication template");
|
||||
|
||||
if (se.df)
|
||||
sc_file_free(se.df);
|
||||
LOG_FUNC_RETURN(ctx, crt.refs[0]);
|
||||
}
|
||||
|
|
|
@ -491,7 +491,6 @@ auth_select_file(struct sc_card *card, const struct sc_path *in_path,
|
|||
auth_current_ef->path.type, sc_print_path(&auth_current_ef->path));
|
||||
|
||||
if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
|
||||
if (auth_current_ef)
|
||||
sc_file_free(auth_current_ef);
|
||||
auth_current_ef = NULL;
|
||||
|
||||
|
@ -516,7 +515,6 @@ auth_select_file(struct sc_card *card, const struct sc_path *in_path,
|
|||
sc_file_dup(&auth_current_df, tmp_file);
|
||||
}
|
||||
else {
|
||||
if (auth_current_ef)
|
||||
sc_file_free(auth_current_ef);
|
||||
|
||||
sc_file_dup(&auth_current_ef, tmp_file);
|
||||
|
@ -531,7 +529,6 @@ auth_select_file(struct sc_card *card, const struct sc_path *in_path,
|
|||
else if (path.type == SC_PATH_TYPE_DF_NAME) {
|
||||
rv = iso_ops->select_file(card, &path, NULL);
|
||||
if (rv) {
|
||||
if (auth_current_ef)
|
||||
sc_file_free(auth_current_ef);
|
||||
auth_current_ef = NULL;
|
||||
}
|
||||
|
@ -993,7 +990,6 @@ auth_create_file(struct sc_card *card, struct sc_file *file)
|
|||
sc_log(card->ctx, "rv %i", rv);
|
||||
}
|
||||
|
||||
if (auth_current_ef)
|
||||
sc_file_free(auth_current_ef);
|
||||
sc_file_dup(&auth_current_ef, file);
|
||||
|
||||
|
|
|
@ -790,7 +790,6 @@ pgp_free_blob(pgp_blob_t *blob)
|
|||
*p = blob->next;
|
||||
}
|
||||
|
||||
if (blob->file)
|
||||
sc_file_free(blob->file);
|
||||
if (blob->data)
|
||||
free(blob->data);
|
||||
|
|
|
@ -2853,7 +2853,6 @@ piv_finish(sc_card_t *card)
|
|||
|
||||
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
if (priv) {
|
||||
if (priv->aid_file)
|
||||
sc_file_free(priv->aid_file);
|
||||
if (priv->w_buf)
|
||||
free(priv->w_buf);
|
||||
|
|
|
@ -86,9 +86,7 @@ static int sc_hsm_select_file(sc_card_t *card,
|
|||
|
||||
if (file_out == NULL) { // Versions before 0.16 of the SmartCard-HSM do not support P2='0C'
|
||||
rv = sc_hsm_select_file(card, in_path, &file);
|
||||
if (file != NULL) {
|
||||
sc_file_free(file);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -1238,7 +1238,6 @@ out:
|
|||
RSA_free(rsa);
|
||||
out2:
|
||||
#endif /* ENABLE_OPENSSL */
|
||||
if (keyfile)
|
||||
sc_file_free(keyfile);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,6 @@ static void sc_card_free(sc_card_t *card)
|
|||
sc_free_apps(card);
|
||||
sc_free_ef_atr(card);
|
||||
|
||||
if (card->ef_dir != NULL)
|
||||
sc_file_free(card->ef_dir);
|
||||
|
||||
free(card->ops);
|
||||
|
@ -120,10 +119,7 @@ static void sc_card_free(sc_card_t *card)
|
|||
card->algorithm_count = 0;
|
||||
}
|
||||
|
||||
if (card->cache.current_ef)
|
||||
sc_file_free(card->cache.current_ef);
|
||||
|
||||
if (card->cache.current_df)
|
||||
sc_file_free(card->cache.current_df);
|
||||
|
||||
if (card->mutex != NULL) {
|
||||
|
|
|
@ -348,7 +348,7 @@ int dnie_read_file(sc_card_t * card,
|
|||
dnie_read_file_err:
|
||||
if (data)
|
||||
free(data);
|
||||
if (file && *file) {
|
||||
if (file) {
|
||||
sc_file_free(*file);
|
||||
*file = NULL;
|
||||
}
|
||||
|
@ -400,10 +400,8 @@ static int dnie_read_certificate(sc_card_t * card, char *certpath, X509 ** cert)
|
|||
buffer = NULL;
|
||||
bufferlen = 0;
|
||||
}
|
||||
if (file) {
|
||||
sc_file_free(file);
|
||||
file = NULL;
|
||||
}
|
||||
if (msg)
|
||||
sc_log(card->ctx, msg);
|
||||
LOG_FUNC_RETURN(card->ctx, res);
|
||||
|
|
|
@ -165,10 +165,8 @@ int sc_enum_apps(sc_card_t *card)
|
|||
card->app_count = 0;
|
||||
|
||||
sc_format_path("3F002F00", &path);
|
||||
if (card->ef_dir != NULL) {
|
||||
sc_file_free(card->ef_dir);
|
||||
card->ef_dir = NULL;
|
||||
}
|
||||
r = sc_select_file(card, &path, &card->ef_dir);
|
||||
LOG_TEST_RET(ctx, r, "Cannot select EF.DIR file");
|
||||
|
||||
|
|
|
@ -236,7 +236,6 @@ iasecc_sm_se_mutual_authentication(struct sc_card *card, unsigned se_num)
|
|||
rv = iasecc_se_get_crt(card, &se, crt);
|
||||
LOG_TEST_RET(ctx, rv, "Cannot get authentication CRT");
|
||||
|
||||
if (se.df)
|
||||
sc_file_free(se.df);
|
||||
|
||||
/* MSE SET Mutual Authentication SK scheme */
|
||||
|
|
|
@ -46,7 +46,6 @@ int dump_ef(sc_card_t * card, const char *path, u8 * buf, size_t * buf_len)
|
|||
sc_format_path(path, &scpath);
|
||||
rv = sc_select_file(card, &scpath, &file);
|
||||
if (rv < 0) {
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -243,7 +243,6 @@ static int infocamere_1200_init(sc_pkcs15_card_t * p15card)
|
|||
|
||||
if (r != SC_SUCCESS || file->size > 255) {
|
||||
/* Not EF.GDO */
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
return SC_ERROR_WRONG_CARD;
|
||||
}
|
||||
|
|
|
@ -60,7 +60,6 @@ int dump_ef(sc_card_t * card, const char *path, u8 * buf, size_t * buf_len)
|
|||
sc_format_path(path, &scpath);
|
||||
rv = sc_select_file(card, &scpath, &file);
|
||||
if (rv < 0) {
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -406,15 +406,11 @@ fix_authentic_ddo(struct sc_pkcs15_card *p15card)
|
|||
* Cleanup this attributes -- default values must be OK.
|
||||
*/
|
||||
if (p15card->card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2) {
|
||||
if (p15card->file_odf != NULL) {
|
||||
sc_file_free(p15card->file_odf);
|
||||
p15card->file_odf = NULL;
|
||||
}
|
||||
if (p15card->file_tokeninfo != NULL) {
|
||||
sc_file_free(p15card->file_tokeninfo);
|
||||
p15card->file_tokeninfo = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -518,18 +514,12 @@ parse_ddo(struct sc_pkcs15_card *p15card, const u8 * buf, size_t buflen)
|
|||
fix_authentic_ddo(p15card);
|
||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||
mem_err:
|
||||
if (p15card->file_odf != NULL) {
|
||||
sc_file_free(p15card->file_odf);
|
||||
p15card->file_odf = NULL;
|
||||
}
|
||||
if (p15card->file_tokeninfo != NULL) {
|
||||
sc_file_free(p15card->file_tokeninfo);
|
||||
p15card->file_tokeninfo = NULL;
|
||||
}
|
||||
if (p15card->file_unusedspace != NULL) {
|
||||
sc_file_free(p15card->file_unusedspace);
|
||||
p15card->file_unusedspace = NULL;
|
||||
}
|
||||
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
|
@ -794,13 +784,9 @@ sc_pkcs15_card_free(struct sc_pkcs15_card *p15card)
|
|||
sc_pkcs15_free_unusedspace(p15card);
|
||||
p15card->unusedspace_read = 0;
|
||||
|
||||
if (p15card->file_app != NULL)
|
||||
sc_file_free(p15card->file_app);
|
||||
if (p15card->file_tokeninfo != NULL)
|
||||
sc_file_free(p15card->file_tokeninfo);
|
||||
if (p15card->file_odf != NULL)
|
||||
sc_file_free(p15card->file_odf);
|
||||
if (p15card->file_unusedspace != NULL)
|
||||
sc_file_free(p15card->file_unusedspace);
|
||||
|
||||
p15card->magic = 0;
|
||||
|
@ -827,22 +813,14 @@ sc_pkcs15_card_clear(struct sc_pkcs15_card *p15card)
|
|||
sc_pkcs15_remove_dfs(p15card);
|
||||
|
||||
p15card->df_list = NULL;
|
||||
if (p15card->file_app != NULL) {
|
||||
sc_file_free(p15card->file_app);
|
||||
p15card->file_app = NULL;
|
||||
}
|
||||
if (p15card->file_tokeninfo != NULL) {
|
||||
sc_file_free(p15card->file_tokeninfo);
|
||||
p15card->file_tokeninfo = NULL;
|
||||
}
|
||||
if (p15card->file_odf != NULL) {
|
||||
sc_file_free(p15card->file_odf);
|
||||
p15card->file_odf = NULL;
|
||||
}
|
||||
if (p15card->file_unusedspace != NULL) {
|
||||
sc_file_free(p15card->file_unusedspace);
|
||||
p15card->file_unusedspace = NULL;
|
||||
}
|
||||
if (p15card->tokeninfo->label != NULL) {
|
||||
free(p15card->tokeninfo->label);
|
||||
p15card->tokeninfo->label = NULL;
|
||||
|
@ -2433,7 +2411,6 @@ sc_pkcs15_read_file(struct sc_pkcs15_card *p15card, const struct sc_path *in_pat
|
|||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||
|
||||
fail_unlock:
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
sc_unlock(p15card->card);
|
||||
LOG_FUNC_RETURN(ctx, r);
|
||||
|
|
|
@ -542,6 +542,8 @@ sc_file_t * sc_file_new(void)
|
|||
void sc_file_free(sc_file_t *file)
|
||||
{
|
||||
unsigned int i;
|
||||
if (file == NULL)
|
||||
return;
|
||||
assert(sc_file_valid(file));
|
||||
file->magic = 0;
|
||||
for (i = 0; i < SC_MAX_AC_OPS; i++)
|
||||
|
@ -600,7 +602,6 @@ void sc_file_dup(sc_file_t **dest, const sc_file_t *src)
|
|||
goto err;
|
||||
return;
|
||||
err:
|
||||
if (newf != NULL)
|
||||
sc_file_free(newf);
|
||||
*dest = NULL;
|
||||
}
|
||||
|
|
|
@ -502,7 +502,6 @@ authentic_free_sdo_data(struct sc_authentic_sdo *sdo)
|
|||
if (!sdo)
|
||||
return;
|
||||
|
||||
if (sdo->file)
|
||||
sc_file_free(sdo->file);
|
||||
|
||||
for (ii=0; ii<rsa_mechs_num; ii++)
|
||||
|
@ -737,7 +736,6 @@ authentic_pkcs15_delete_rsa_sdo (struct sc_profile *profile, struct sc_pkcs15_ca
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -114,7 +114,6 @@ static int cflex_erase_card(struct sc_profile *profile, sc_pkcs15_card_t *p15car
|
|||
|
||||
|
||||
out: /* Forget all cached keys, the pin files on card are all gone. */
|
||||
if (userpinfile)
|
||||
sc_file_free(userpinfile);
|
||||
|
||||
sc_free_apps(p15card->card);
|
||||
|
@ -308,9 +307,7 @@ cflex_create_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_pkcs15_obj
|
|||
|
||||
key_info->key_reference = 0;
|
||||
|
||||
out: if (prkf)
|
||||
sc_file_free(prkf);
|
||||
if (pukf)
|
||||
out: sc_file_free(prkf);
|
||||
sc_file_free(pukf);
|
||||
return r;
|
||||
}
|
||||
|
@ -372,9 +369,7 @@ cflex_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
|
||||
invert_buf(pubkey->u.rsa.modulus.data, raw_pubkey, pubkey->u.rsa.modulus.len);
|
||||
|
||||
out: if (pukf)
|
||||
sc_file_free(pukf);
|
||||
if (prkf)
|
||||
out: sc_file_free(pukf);
|
||||
sc_file_free(prkf);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -624,11 +624,8 @@ static int epass2003_pkcs15_generate_key(struct sc_profile *profile,
|
|||
free(gendat.modulus);
|
||||
|
||||
err:
|
||||
if (pukf)
|
||||
sc_file_free(pukf);
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
if (tfile)
|
||||
sc_file_free(tfile);
|
||||
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
|
||||
|
|
|
@ -500,7 +500,6 @@ gpk_store_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
if (r >= 0)
|
||||
r = gpk_store_pk(profile, p15card, keyfile, &data);
|
||||
|
||||
if (keyfile)
|
||||
sc_file_free(keyfile);
|
||||
return r;
|
||||
}
|
||||
|
@ -595,7 +594,6 @@ gpk_pkfile_create(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file_t *f
|
|||
if (r >= 0)
|
||||
r = sc_pkcs15init_authenticate(profile, p15card, file,
|
||||
SC_AC_OP_UPDATE);
|
||||
if (found)
|
||||
sc_file_free(found);
|
||||
|
||||
return r;
|
||||
|
@ -727,8 +725,7 @@ gpk_pkfile_init_public(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file
|
|||
r = sc_append_record(p15card->card, sysrec, sizeof(sysrec), 0);
|
||||
}
|
||||
|
||||
out: if (tmp)
|
||||
sc_file_free(tmp);
|
||||
out: sc_file_free(tmp);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -300,7 +300,6 @@ iasecc_pkcs15_select_key_reference(struct sc_profile *profile, struct sc_pkcs15_
|
|||
key_info->key_reference = idx | IASECC_OBJECT_REF_LOCAL;
|
||||
sc_log(ctx, "selected key reference %i", key_info->key_reference);
|
||||
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||
}
|
||||
|
@ -376,7 +375,7 @@ iasecc_sdo_set_key_acls_from_profile(struct sc_profile *profile, struct sc_card
|
|||
|
||||
/* Convert PKCS15 ACLs to SE ACLs */
|
||||
rv = iasecc_file_convert_acls(ctx, profile, file);
|
||||
if (rv < 0 && file)
|
||||
if (rv < 0)
|
||||
sc_file_free(file);
|
||||
LOG_TEST_RET(ctx, rv, "Cannot convert profile ACLs");
|
||||
|
||||
|
@ -401,7 +400,6 @@ iasecc_sdo_set_key_acls_from_profile(struct sc_profile *profile, struct sc_card
|
|||
}
|
||||
else if (acl->method == SC_AC_SEN || acl->method == SC_AC_PRO || acl->method == SC_AC_AUT) {
|
||||
if ((acl->key_ref & 0xF) == 0 || (acl->key_ref & 0xF) == 0xF) {
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid SE reference");
|
||||
}
|
||||
|
@ -416,13 +414,11 @@ iasecc_sdo_set_key_acls_from_profile(struct sc_profile *profile, struct sc_card
|
|||
scb[cntr++] = acl->key_ref | IASECC_SCB_METHOD_EXT_AUTH;
|
||||
}
|
||||
else {
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Unknown SCB method");
|
||||
}
|
||||
}
|
||||
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
|
||||
/* Copy ACLs into the DOCP*/
|
||||
|
@ -853,7 +849,6 @@ iasecc_sdo_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
card->caps &= ~SC_CARD_CAP_USE_FCI_AC;
|
||||
rv = sc_pkcs15init_authenticate(profile, p15card, dummy_file, SC_AC_OP_UPDATE);
|
||||
card->caps = caps;
|
||||
if (dummy_file)
|
||||
sc_file_free(dummy_file);
|
||||
|
||||
LOG_TEST_RET(ctx, rv, "SDO PRIVATE KEY UPDATE authentication failed");
|
||||
|
@ -1037,11 +1032,8 @@ iasecc_pkcs15_create_key_slot(struct sc_profile *profile, struct sc_pkcs15_card
|
|||
LOG_TEST_GOTO_ERR(ctx, rv, "create key slot: cannot create public key: ctl failed");
|
||||
|
||||
err:
|
||||
if (file_p_prvkey)
|
||||
sc_file_free(file_p_prvkey);
|
||||
if (file_p_pubkey)
|
||||
sc_file_free(file_p_pubkey);
|
||||
if (parent)
|
||||
sc_file_free(parent);
|
||||
|
||||
LOG_FUNC_RETURN(ctx, rv);
|
||||
|
@ -1141,7 +1133,6 @@ iasecc_pkcs15_generate_key(struct sc_profile *profile, sc_pkcs15_card_t *p15card
|
|||
rv = sc_select_file(card, &file->path, NULL);
|
||||
LOG_TEST_RET(ctx, rv, "DF for private objects not defined");
|
||||
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
|
||||
rv = iasecc_sdo_convert_to_file(card, sdo_prvkey, &file);
|
||||
|
@ -1234,7 +1225,6 @@ iasecc_pkcs15_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15ca
|
|||
rv = sc_select_file(card, &file->path, NULL);
|
||||
LOG_TEST_RET(ctx, rv, "failed to select parent DF");
|
||||
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
|
||||
key_info->access_flags &= ~SC_PKCS15_PRKEY_ACCESS_LOCAL;
|
||||
|
@ -1303,7 +1293,6 @@ iasecc_pkcs15_delete_sdo (struct sc_profile *profile, struct sc_pkcs15_card *p15
|
|||
rv = sc_pkcs15init_authenticate(profile, p15card, dummy_file, SC_AC_OP_UPDATE);
|
||||
card->caps = save_card_caps;
|
||||
|
||||
if (dummy_file)
|
||||
sc_file_free(dummy_file);
|
||||
|
||||
if (rv < 0) {
|
||||
|
@ -1692,7 +1681,6 @@ iasecc_store_cert(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
|||
rv = iasecc_pkcs15_fix_file_access(p15card, pfile, object);
|
||||
LOG_TEST_RET(ctx, rv, "encode file access rules failed");
|
||||
|
||||
if (pfile)
|
||||
sc_file_free(pfile);
|
||||
|
||||
/* NOT_IMPLEMENTED error code indicates to the upper call to execute the default 'store data' procedure */
|
||||
|
@ -1801,12 +1789,8 @@ iasecc_store_data_object(struct sc_pkcs15_card *p15card, struct sc_profile *prof
|
|||
if (path)
|
||||
*path = file->path;
|
||||
|
||||
if (parent)
|
||||
sc_file_free(parent);
|
||||
|
||||
sc_file_free(file);
|
||||
|
||||
if (cfile)
|
||||
sc_file_free(cfile);
|
||||
|
||||
LOG_FUNC_RETURN(ctx, rv);
|
||||
|
|
|
@ -324,9 +324,7 @@ jcop_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
free(keybuf);
|
||||
if (delete_ok)
|
||||
sc_pkcs15init_rmdir(p15card, profile, temppubfile);
|
||||
if (keyfile)
|
||||
sc_file_free(keyfile);
|
||||
if (temppubfile)
|
||||
sc_file_free(temppubfile);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -467,7 +467,6 @@ sc_pkcs15init_set_p15card(struct sc_profile *profile, struct sc_pkcs15_card *p15
|
|||
}
|
||||
}
|
||||
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
}
|
||||
|
||||
|
@ -2842,7 +2841,6 @@ sc_pkcs15init_update_any_df(struct sc_pkcs15_card *p15card,
|
|||
}
|
||||
free(buf);
|
||||
}
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
|
||||
LOG_TEST_RET(ctx, r, "Failed to encode or update xDF");
|
||||
|
@ -3253,7 +3251,6 @@ sc_pkcs15init_update_certificate(struct sc_pkcs15_card *p15card,
|
|||
profile->dirty = 1;
|
||||
|
||||
done:
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
|
||||
LOG_FUNC_RETURN(ctx, r);
|
||||
|
@ -3545,7 +3542,6 @@ sc_pkcs15init_authenticate(struct sc_profile *profile, struct sc_pkcs15_card *p1
|
|||
r = sc_pkcs15init_verify_secret(profile, p15card, file_tmp ? file_tmp : file, acl->method, acl->key_ref);
|
||||
}
|
||||
|
||||
if (file_tmp)
|
||||
sc_file_free(file_tmp);
|
||||
|
||||
LOG_FUNC_RETURN(ctx, r);
|
||||
|
@ -3630,7 +3626,6 @@ sc_pkcs15init_create_file(struct sc_profile *profile, struct sc_pkcs15_card *p15
|
|||
r = sc_create_file(p15card->card, file);
|
||||
LOG_TEST_RET(ctx, r, "Create file failed");
|
||||
|
||||
if (parent)
|
||||
sc_file_free(parent);
|
||||
LOG_FUNC_RETURN(ctx, r);
|
||||
}
|
||||
|
|
|
@ -185,7 +185,6 @@ myeid_init_card(sc_profile_t *profile,
|
|||
sc_format_path("3F00", &path);
|
||||
r = sc_select_file(p15card->card, &path, &file);
|
||||
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
|
||||
LOG_FUNC_RETURN(p15card->card->ctx, r);
|
||||
|
@ -231,7 +230,6 @@ myeid_create_dir(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file_t *df
|
|||
sc_log(ctx, "Create '%s'", create_dfs[ii]);
|
||||
|
||||
r = sc_profile_get_file(profile, create_dfs[ii], &file);
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
if (r) {
|
||||
sc_log(ctx, "Inconsistent profile: cannot find %s", create_dfs[ii]);
|
||||
|
@ -530,7 +528,6 @@ myeid_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_UPDATE);
|
||||
LOG_TEST_RET(ctx, r, "No authorisation to store MyEID private key");
|
||||
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
|
||||
/* Fill in data structure */
|
||||
|
@ -722,7 +719,6 @@ myeid_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
}
|
||||
}
|
||||
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
|
||||
LOG_FUNC_RETURN(ctx, r);
|
||||
|
|
|
@ -152,7 +152,6 @@ awp_new_file(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
|||
if (otag) {
|
||||
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "obj template %s",otag);
|
||||
if (sc_profile_get_file(profile, otag, &ofile) < 0) {
|
||||
if (ifile)
|
||||
sc_file_free(ifile);
|
||||
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "profile does not defines template '%s'", name);
|
||||
return SC_ERROR_INCONSISTENT_PROFILE;
|
||||
|
@ -531,8 +530,8 @@ awp_update_container(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
|||
}
|
||||
|
||||
done:
|
||||
if (clist) sc_file_free(clist);
|
||||
if (file) sc_file_free(file);
|
||||
sc_file_free(clist);
|
||||
sc_file_free(file);
|
||||
if (list) free(list);
|
||||
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
||||
|
@ -1392,9 +1391,7 @@ awp_update_df_create_cert(struct sc_pkcs15_card *p15card, struct sc_profile *pro
|
|||
|
||||
awp_free_cert_info(&icert);
|
||||
|
||||
if (info_file)
|
||||
sc_file_free(info_file);
|
||||
if (obj_file)
|
||||
sc_file_free(obj_file);
|
||||
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
||||
|
@ -1478,7 +1475,6 @@ awp_update_df_create_prvkey(struct sc_pkcs15_card *p15card, struct sc_profile *p
|
|||
err:
|
||||
if (p15cert)
|
||||
sc_pkcs15_free_certificate(p15cert);
|
||||
if (info_file)
|
||||
sc_file_free(info_file);
|
||||
if (cert_obj)
|
||||
awp_free_cert_info(&icert);
|
||||
|
@ -1532,7 +1528,6 @@ awp_update_df_create_pubkey(struct sc_pkcs15_card *p15card, struct sc_profile *p
|
|||
awp_free_key_info(&ikey);
|
||||
|
||||
err:
|
||||
if (info_file)
|
||||
sc_file_free(info_file);
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
||||
}
|
||||
|
@ -1572,9 +1567,7 @@ awp_update_df_create_data(struct sc_pkcs15_card *p15card, struct sc_profile *pro
|
|||
|
||||
awp_free_data_info(&idata);
|
||||
|
||||
if (info_file)
|
||||
sc_file_free(info_file);
|
||||
if (obj_file)
|
||||
sc_file_free(obj_file);
|
||||
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
||||
|
@ -1689,8 +1682,8 @@ awp_delete_from_container(struct sc_pkcs15_card *p15card,
|
|||
if (rv > 0)
|
||||
rv = 0;
|
||||
|
||||
if (buff) free(buff);
|
||||
if (clist) sc_file_free(clist);
|
||||
free(buff);
|
||||
sc_file_free(clist);
|
||||
sc_file_free(file);
|
||||
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
||||
|
@ -1766,7 +1759,6 @@ done:
|
|||
if (buff)
|
||||
free(buff);
|
||||
sc_file_free(lst);
|
||||
if (lst_file)
|
||||
sc_file_free(lst_file);
|
||||
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
||||
|
|
|
@ -111,7 +111,6 @@ cosm_write_tokeninfo (struct sc_pkcs15_card *p15card, struct sc_profile *profile
|
|||
rv = 0;
|
||||
|
||||
err:
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
free(buffer);
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
||||
|
@ -322,7 +321,6 @@ cosm_create_reference_data(struct sc_profile *profile, struct sc_pkcs15_card *p1
|
|||
rv = sc_pkcs15init_update_file(profile, p15card, file, oberthur_puk, sizeof(oberthur_puk));
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to update pukfile");
|
||||
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
}
|
||||
|
||||
|
@ -714,7 +712,6 @@ cosm_create_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
key_info->key_reference = file->path.value[file->path.len - 1];
|
||||
|
||||
err:
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
||||
|
@ -761,7 +758,6 @@ cosm_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
rv = sc_card_ctl(p15card->card, SC_CARDCTL_OBERTHUR_UPDATE_KEY, &update_info);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot update private key");
|
||||
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
||||
|
|
|
@ -73,7 +73,6 @@ static int create_sysdf(sc_profile_t *profile, sc_card_t *card, const char *name
|
|||
SC_AC_NEVER, SC_AC_KEY_REF_NONE);
|
||||
if (r == SC_SUCCESS)
|
||||
r = sc_create_file(card, file);
|
||||
assert(file);
|
||||
sc_file_free(file);
|
||||
}
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
|
||||
|
@ -99,7 +98,6 @@ static int rtecp_init(sc_profile_t *profile, sc_pkcs15_card_t *p15card)
|
|||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Get MF info failed");
|
||||
assert(file);
|
||||
r = sc_create_file(card, file);
|
||||
assert(file);
|
||||
sc_file_free(file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Create MF failed");
|
||||
|
||||
|
@ -107,7 +105,6 @@ static int rtecp_init(sc_profile_t *profile, sc_pkcs15_card_t *p15card)
|
|||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Get DIR file info failed");
|
||||
assert(file);
|
||||
r = sc_create_file(card, file);
|
||||
assert(file);
|
||||
sc_file_free(file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Create DIR file failed");
|
||||
|
||||
|
@ -346,7 +343,6 @@ static int rtecp_create_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
r = sc_file_add_acl_entry(file, SC_AC_OP_CREATE, SC_AC_CHV, auth_id);
|
||||
if (r == SC_SUCCESS)
|
||||
r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_CREATE);
|
||||
assert(file);
|
||||
sc_file_free(file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Authenticate failed");
|
||||
|
||||
|
@ -403,7 +399,6 @@ static int rtecp_create_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
sc_log(ctx, "create public key file id:%04i", file->id);
|
||||
r = sc_create_file(p15card->card, file);
|
||||
}
|
||||
assert(file);
|
||||
sc_file_free(file);
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, r);
|
||||
}
|
||||
|
|
|
@ -417,7 +417,6 @@ setcos_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
r = sc_card_ctl(p15card->card, SC_CARDCTL_SETCOS_GENERATE_STORE_KEY, &args);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Card control 'GENERATE_STORE_KEY' failed");
|
||||
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, r);
|
||||
|
|
|
@ -117,7 +117,6 @@ static int westcos_pkcs15_create_pin(sc_profile_t *profile,
|
|||
if(r) return (r);
|
||||
}
|
||||
|
||||
if(pinfile)
|
||||
sc_file_free(pinfile);
|
||||
|
||||
if(pin != NULL)
|
||||
|
@ -314,7 +313,6 @@ out:
|
|||
BN_free(bn);
|
||||
if(rsa)
|
||||
RSA_free(rsa);
|
||||
if(prkf)
|
||||
sc_file_free(prkf);
|
||||
|
||||
return r;
|
||||
|
|
|
@ -260,7 +260,6 @@ static int usage(int (*func)(int, char **))
|
|||
|
||||
static void die(int ret)
|
||||
{
|
||||
if (current_file != NULL)
|
||||
sc_file_free(current_file);
|
||||
if (card) {
|
||||
sc_unlock(card);
|
||||
|
@ -684,7 +683,6 @@ static int do_cd(int argc, char **argv)
|
|||
printf("unable to go up: %s\n", sc_strerror(r));
|
||||
return -1;
|
||||
}
|
||||
if (current_file)
|
||||
sc_file_free(current_file);
|
||||
current_file = file;
|
||||
current_path = path;
|
||||
|
@ -705,7 +703,6 @@ static int do_cd(int argc, char **argv)
|
|||
return -1;
|
||||
}
|
||||
current_path = path;
|
||||
if (current_file)
|
||||
sc_file_free(current_file);
|
||||
current_file = file;
|
||||
|
||||
|
@ -818,7 +815,6 @@ static int do_cat(int argc, char **argv)
|
|||
err = 0;
|
||||
err:
|
||||
if (not_current) {
|
||||
if (file != NULL)
|
||||
sc_file_free(file);
|
||||
select_current_path_or_die();
|
||||
}
|
||||
|
@ -1318,7 +1314,6 @@ static int do_get(int argc, char **argv)
|
|||
|
||||
err = 0;
|
||||
err:
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
if (outf != NULL && outf != stdout)
|
||||
fclose(outf);
|
||||
|
@ -1492,7 +1487,6 @@ static int do_put(int argc, char **argv)
|
|||
|
||||
err = 0;
|
||||
err:
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
if (outf)
|
||||
fclose(outf);
|
||||
|
@ -1746,7 +1740,6 @@ err:
|
|||
if (buf)
|
||||
free(buf);
|
||||
if (not_current) {
|
||||
if (file)
|
||||
sc_file_free(file);
|
||||
select_current_path_or_die();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue