Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dtrust-tool: fix memory leak #3171

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
dtrust-tool: fix memory leak
If `qespin1` and `qespin2` doesn't match, `qespin2` was neither cleared
nor freed;
  • Loading branch information
hamarituc committed Jun 3, 2024
commit 81a01ee54d15df5070f85ace9a61971e3219234a
9 changes: 4 additions & 5 deletions src/tools/dtrust-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,19 @@ unlock_transport_protection(sc_card_t *card)
r = util_getpass(&qespin1, &qespin1_len, stdin);
if (r < 0 || qespin1 == NULL) {
fprintf(stderr, "Unable to get PIN");
goto fail_qespin1;
goto fail;
}

printf("Enter new Signature PIN again:");
r = util_getpass(&qespin2, &qespin1_len, stdin);
if (r < 0 || qespin2 == NULL) {
fprintf(stderr, "Unable to get PIN");
goto fail_qespin2;
goto fail;
}

if (strcmp(qespin1, qespin2)) {
fprintf(stderr, "New signature PINs doesn't match.\n");
goto fail_qespin2;
goto fail;
}
data.pin1.data = (u8 *)tpin;
data.pin1.len = strlen(tpin);
Expand All @@ -196,18 +196,17 @@ unlock_transport_protection(sc_card_t *card)
else
printf("Can't change pin: %s\n", sc_strerror(r));

fail:
if (qespin2 != NULL) {
sc_mem_clear(qespin2, qespin2_len);
free(qespin2);
}

fail_qespin2:
if (qespin1 != NULL) {
sc_mem_clear(qespin1, qespin1_len);
free(qespin1);
}

fail_qespin1:
if (tpin != NULL) {
sc_mem_clear(tpin, tpin_len);
free(tpin);
Expand Down