From fff1963931e11675d9b62ba4cdbb5a3d5e4a5904 Mon Sep 17 00:00:00 2001 From: "viktor.tarasov" Date: Wed, 26 May 2010 14:33:01 +0000 Subject: [PATCH] pkcs15init: do not reuse existing file when storing object data or updating certificate merged with r4380:4380 of https://www.opensc-project.org/svn/opensc/branches/vtarasov/opensc-sm.trunk git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4382 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/pkcs15init/pkcs15-lib.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pkcs15init/pkcs15-lib.c b/src/pkcs15init/pkcs15-lib.c index 2adcb81a..84ed4956 100644 --- a/src/pkcs15init/pkcs15-lib.c +++ b/src/pkcs15init/pkcs15-lib.c @@ -1694,8 +1694,12 @@ sc_pkcs15init_store_data(struct sc_pkcs15_card *p15card, struct sc_profile *prof file->path.index = 0; file->path.count = -1; } - r = sc_pkcs15init_update_file(profile, p15card, file, - data->value, data->len); + + r = sc_pkcs15init_delete_by_path(profile, p15card, &file->path); + if (r && r != SC_ERROR_FILE_NOT_FOUND) + SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot delete file"); + + r = sc_pkcs15init_update_file(profile, p15card, file, data->value, data->len); *path = file->path; @@ -2770,7 +2774,7 @@ sc_pkcs15init_update_certificate(struct sc_pkcs15_card *p15card, SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Failed to select cert file"); /* If the new cert doesn't fit in the EF, delete it and make the same, but bigger EF */ - if (file->size < certlen) { + if (file->size != certlen) { struct sc_file *parent = NULL; r = sc_pkcs15init_delete_by_path(profile, p15card, path); @@ -3237,7 +3241,7 @@ sc_pkcs15init_update_file(struct sc_profile *profile, struct sc_context *ctx = p15card->card->ctx; struct sc_file *selected_file = NULL; void *copy = NULL; - int r, need_to_zap = 0; + int r; SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL); sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "path:%s; datalen:%i\n", sc_print_path(&file->path), datalen);