diff --git a/src/libopensc/iso7816.c b/src/libopensc/iso7816.c index 53cf2e92..ccebbb01 100644 --- a/src/libopensc/iso7816.c +++ b/src/libopensc/iso7816.c @@ -357,7 +357,7 @@ static int iso7816_process_fci(sc_card_t *card, sc_file_t *file, } name[taglen] = 0; if (ctx->debug >= 3) - sc_debug(ctx, "File name: %s\n", name); + sc_debug(ctx, " File name: %s\n", name); } tag = sc_asn1_find_tag(ctx, p, len, 0x85, &taglen); if (tag != NULL && taglen) { @@ -598,15 +598,20 @@ static int iso7816_delete_file(sc_card_t *card, const sc_path_t *path) sc_apdu_t apdu; SC_FUNC_CALLED(card->ctx, 1); - if (path->type != SC_PATH_TYPE_FILE_ID && path->len != 2) { + if (path->type != SC_PATH_TYPE_FILE_ID || (path->len != 0 && path->len != 2)) { sc_error(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n"); SC_FUNC_RETURN(card->ctx, 1, SC_ERROR_INVALID_ARGUMENTS); } - sbuf[0] = path->value[0]; - sbuf[1] = path->value[1]; - sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xE4, 0x00, 0x00); - apdu.lc = 2; - apdu.datalen = 2; + + if (path->len == 2) { + sbuf[0] = path->value[0]; + sbuf[1] = path->value[1]; + sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xE4, 0x00, 0x00); + apdu.lc = 2; + apdu.datalen = 2; + } + else /* No file ID given: means currently selected file */ + sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0xE4, 0x00, 0x00); apdu.data = sbuf; r = sc_transmit_apdu(card, &apdu);