From 3a68ba695b538f55f4bf45fe8f79ffb9b00ac5c1 Mon Sep 17 00:00:00 2001 From: okir Date: Thu, 31 Jul 2003 21:16:15 +0000 Subject: [PATCH] - warn if EF is too small for the amount of data we want to write git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1323 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/pkcs15init/pkcs15-lib.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pkcs15init/pkcs15-lib.c b/src/pkcs15init/pkcs15-lib.c index 5195a952..9eb854c1 100644 --- a/src/pkcs15init/pkcs15-lib.c +++ b/src/pkcs15init/pkcs15-lib.c @@ -1976,26 +1976,37 @@ int sc_pkcs15init_update_file(struct sc_profile *profile, struct sc_card *card, struct sc_file *file, void *data, unsigned int datalen) { + struct sc_file *info = NULL; int r; card->ctx->log_errors = 0; - if ((r = sc_select_file(card, &file->path, NULL)) < 0) { + if ((r = sc_select_file(card, &file->path, &info)) < 0) { card->ctx->log_errors = 1; /* Create file if it doesn't exist */ if (file->size < datalen) file->size = datalen; if (r != SC_ERROR_FILE_NOT_FOUND || (r = sc_pkcs15init_create_file(profile, card, file)) < 0 - || (r = sc_select_file(card, &file->path, NULL)) < 0) + || (r = sc_select_file(card, &file->path, &info)) < 0) return r; } card->ctx->log_errors = 1; + if (info->size < datalen) { + char buf[16]; + + sc_bin_to_hex(file->path.value, file->path.len, buf, sizeof(buf), ""); + p15init_error("File %s too small - please increase size in profile", buf); + sc_file_free(info); + return SC_ERROR_TOO_MANY_OBJECTS; + } + /* Present authentication info needed */ r = sc_pkcs15init_authenticate(profile, card, file, SC_AC_OP_UPDATE); if (r >= 0 && datalen) r = sc_update_binary(card, 0, (const u8 *) data, datalen, 0); + sc_file_free(info); return r; }