Skip to content

Commit 84152c9

Browse files
committed
pkcs15init segfault
pkcs15init/pkcs15-lib.c in sc_pkcs15init_add_app had: /* FIXME: what to do if sc_pkcs15init_update_dir failed? */ This fixes the problem. Fixes: #2398 in that it will not segfault. On branch epass2003-init Changes to be committed: modified: ../pkcs15init/pkcs15-lib.c
1 parent 11bc288 commit 84152c9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/pkcs15init/pkcs15-lib.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,9 +912,20 @@ sc_pkcs15init_add_app(struct sc_card *card, struct sc_profile *profile,
912912
if (r >= 0) {
913913
r = sc_pkcs15init_update_tokeninfo(p15card, profile);
914914
} else {
915-
/* FIXME: what to do if sc_pkcs15init_update_dir failed? */
916-
free(app->label);
917-
free(app); /* unused */
915+
/* FIXED: what to do if sc_pkcs15init_update_dir failed? */
916+
/* sc_pkcs15init_update_dir may add app to card->app[] */
917+
int found = 0;
918+
int i;
919+
for (i = 0; i < card->app_count; i++) {
920+
if (card->app[i] == app) {
921+
found = 1;
922+
break;
923+
}
924+
}
925+
if (found == 0) { /* not in card->app[] free it */
926+
free(app->label);
927+
free(app); /* unused */
928+
}
918929
}
919930
}
920931
else {

0 commit comments

Comments
 (0)