handle checking of file output in sc_select_file

fixes https://github.com/OpenSC/OpenSC/issues/576
This commit is contained in:
Frank Morgner 2015-10-14 23:22:35 +02:00
parent bcf9b2bc84
commit e1073c09ea
2 changed files with 16 additions and 6 deletions

View File

@ -689,6 +689,12 @@ int sc_select_file(sc_card_t *card, const sc_path_t *in_path, sc_file_t **file)
if (r != SC_SUCCESS)
pbuf[0] = '\0';
/* FIXME We should be a bit less strict and let the upper layers do
* the initialization (including reuse of existing file objects). We
* implemented this here because we are lazy. */
if (file != NULL)
*file = NULL;
sc_log(card->ctx, "called; type=%d, path=%s", in_path->type, pbuf);
if (in_path->len > SC_MAX_PATH_SIZE)
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
@ -713,9 +719,16 @@ int sc_select_file(sc_card_t *card, const sc_path_t *in_path, sc_file_t **file)
r = card->ops->select_file(card, in_path, file);
LOG_TEST_RET(card->ctx, r, "'SELECT' error");
/* Remember file path */
if (file && *file)
(*file)->path = *in_path;
if (file) {
if (*file)
/* Remember file path */
(*file)->path = *in_path;
else
/* FIXME We should be a bit less strict and let the upper layers do
* the error checking. We implemented this here because we are
* lazy. */
r = SC_ERROR_INVALID_DATA;
}
LOG_FUNC_RETURN(card->ctx, r);
}

View File

@ -457,9 +457,6 @@ iso7816_select_file(struct sc_card *card, const struct sc_path *in_path, struct
pathlen = in_path->len;
pathtype = in_path->type;
if (file_out != NULL) {
*file_out = NULL;
}
if (in_path->aid.len) {
if (!pathlen) {
memcpy(path, in_path->aid.value, in_path->aid.len);