tpm2-tools/0008-tpm2_checkquote-Fix-memory-leaks-malloced-buffer-not.patch
Štěpán Horáček 8b31466bc1 Backport upstream fixes
Resolves: RHEL-164796

Signed-off-by: Štěpán Horáček <shoracek@redhat.com>
2026-05-25 20:52:48 +02:00

48 lines
1.6 KiB
Diff

From 9ae92d6db68bdf7f7691e84a6f95c3e064a2d96f Mon Sep 17 00:00:00 2001
From: Dimitrios Siganos <dimitris@siganos.org>
Date: Sun, 9 Nov 2025 11:53:21 +0000
Subject: [PATCH 08/30] 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>
---
tools/misc/tpm2_checkquote.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/misc/tpm2_checkquote.c b/tools/misc/tpm2_checkquote.c
index 648a383f..259d9c62 100644
--- a/tools/misc/tpm2_checkquote.c
+++ b/tools/misc/tpm2_checkquote.c
@@ -405,7 +405,7 @@ static bool parse_marshaled_selection_data(FILE *pcr_input,
if (!file_read_bytes_from_file(pcr_input, buffer, &size, ctx.pcr_file_path)) {
LOG_ERR("Failed to read PCR selection from file");
- return false;
+ goto error;
}
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,
if (pcrs->count > ARRAY_LEN(pcrs->pcr_values)) {
LOG_ERR("Malformed PCR file, pcr count cannot be greater than %zu, got: %" PRIu64 " ",
ARRAY_LEN(pcrs->pcr_values), le64toh((UINT64)pcrs->count));
- return false;
+ goto error;
}
for (i = 0; i < pcrs->count; i++) {
@@ -433,6 +433,7 @@ static bool parse_marshaled_selection_data(FILE *pcr_input,
goto error;
}
}
+ free(buffer);
return true;
error:
--
2.54.0