Skip to content

Commit 06c8eb7

Browse files
committed
tpm2_checkquote: Fix memory leaks, malloced buffer not always freed
A buffer allocated with malloc was not freed in all possible paths, not even in the success path. Signed-off-by: Dimitrios Siganos <dimitris@siganos.org>
1 parent 6202f39 commit 06c8eb7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tools/misc/tpm2_checkquote.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static bool parse_marshaled_selection_data(FILE *pcr_input,
405405

406406
if (!file_read_bytes_from_file(pcr_input, buffer, &size, ctx.pcr_file_path)) {
407407
LOG_ERR("Failed to read PCR selection from file");
408-
return false;
408+
goto error;
409409
}
410410

411411
rc = Tss2_MU_TPML_PCR_SELECTION_Unmarshal(buffer, size, &offset, pcr_select);
@@ -422,7 +422,7 @@ static bool parse_marshaled_selection_data(FILE *pcr_input,
422422
if (pcrs->count > ARRAY_LEN(pcrs->pcr_values)) {
423423
LOG_ERR("Malformed PCR file, pcr count cannot be greater than %zu, got: %" PRIu64 " ",
424424
ARRAY_LEN(pcrs->pcr_values), le64toh((UINT64)pcrs->count));
425-
return false;
425+
goto error;
426426
}
427427

428428
for (i = 0; i < pcrs->count; i++) {
@@ -433,6 +433,7 @@ static bool parse_marshaled_selection_data(FILE *pcr_input,
433433
goto error;
434434
}
435435
}
436+
free(buffer);
436437
return true;
437438

438439
error:

0 commit comments

Comments
 (0)