Skip to content

Commit

Permalink
idprime: Use temporary variable instead of messing up the passed one
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakuje committed Dec 4, 2020
1 parent 78cdab9 commit f015746
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/libopensc/card-idprime.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ static int idprime_get_token_name(sc_card_t* card, char** tname)
sc_path_t tinfo_path = {"\x00\x00", 2, 0, 0, SC_PATH_TYPE_PATH, {"", 0}};
sc_file_t *file = NULL;
u8 buf[2];
char *name;
int r;

LOG_FUNC_CALLED(card->ctx);
Expand Down Expand Up @@ -445,20 +446,22 @@ static int idprime_get_token_name(sc_card_t* card, char** tname)
}
sc_file_free(file);

*tname = malloc(buf[1]);
if (*tname == NULL) {
name = malloc(buf[1]);
if (name == NULL) {
LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
}

r = iso_ops->read_binary(card, 2, (unsigned char *)*tname, buf[1], 0);
r = iso_ops->read_binary(card, 2, (unsigned char *)name, buf[1], 0);
if (r < 1) {
free(*tname);
free(name);
LOG_FUNC_RETURN(card->ctx, r);
}

if ((*tname)[r-1] != '\0') {
(*tname)[r-1] = '\0';
if (name[r-1] != '\0') {
name[r-1] = '\0';
}
*tname = name;

LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
}

Expand Down

0 comments on commit f015746

Please sign in to comment.