From 0e86da9d66222d1f6824bef33d2151d5e43696b3 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Mon, 13 Mar 2023 19:29:04 +0100 Subject: [PATCH] zipl: extract_signature: fix memory leak of @signature Fix memory leak @signature in case of an unsupported signature type. Reviewed-by: Steffen Eiden Reviewed-by: Stefan Haberland Signed-off-by: Marc Hartmayer Signed-off-by: Steffen Eiden --- zipl/src/bootmap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zipl/src/bootmap.c b/zipl/src/bootmap.c index 2751d16c..2e590dee 100644 --- a/zipl/src/bootmap.c +++ b/zipl/src/bootmap.c @@ -511,9 +511,6 @@ extract_signature(const char *filename, void **ret_signature, memcpy(signature, buffer + size - signature_size - sizeof(*file_sig), signature_size); - *ret_signature = signature; - sig_head->length = signature_size; - switch (file_sig->id_type) { case PKEY_ID_PKCS7: sig_head->format = PKCS7_FORMAT; @@ -522,8 +519,12 @@ extract_signature(const char *filename, void **ret_signature, error_text("Unsupported signature type %02x", file_sig->id_type); signature_size = 0; + free(signature); goto out; } + + sig_head->length = signature_size; + *ret_signature = signature; /* return size of signature and corresponding header */ signature_size += sizeof(*file_sig); out: