From 1f6f233f8714e36f7623b6af08dc3154c3b390f8 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 26 Oct 2021 12:39:16 +0200 Subject: [PATCH] sd-stub: Fix possible memory leak --- src/boot/efi/stub.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index 52d26e7cd2..4de23792b5 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -172,6 +172,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { UINTN addrs[_SECTION_MAX] = {}; UINTN szs[_SECTION_MAX] = {}; CHAR8 *cmdline = NULL; + _cleanup_freepool_ CHAR8 *cmdline_owned = NULL; EFI_STATUS err; InitializeLib(image, sys_table); @@ -204,18 +205,13 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { /* if we are not in secure boot mode, or none was provided, accept a custom command line and replace the built-in one */ if ((!secure_boot_enabled() || cmdline_len == 0) && loaded_image->LoadOptionsSize > 0 && *(CHAR16 *) loaded_image->LoadOptions > 0x1F) { - CHAR16 *options; - CHAR8 *line; - - options = (CHAR16 *)loaded_image->LoadOptions; cmdline_len = (loaded_image->LoadOptionsSize / sizeof(CHAR16)) * sizeof(CHAR8); - line = AllocatePool(cmdline_len); - if (!line) + cmdline = cmdline_owned = AllocatePool(cmdline_len); + if (!cmdline) return log_oom(); for (UINTN i = 0; i < cmdline_len; i++) - line[i] = options[i]; - cmdline = line; + cmdline[i] = ((CHAR16 *) loaded_image->LoadOptions)[i]; /* Let's measure the passed kernel command line into the TPM. Note that this possibly * duplicates what we already did in the boot menu, if that was already used. However, since