From 959f5e4e993a82020fef48c7e7c012a44074645c Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 18 Nov 2019 13:58:46 -0500 Subject: [PATCH 43/62] Actually check for errors from set_second_stage() This changes shim_init() to check for errors from set_second_stage(). In order to make that work, it also does the following: - correctly /always/ allocate second_stage, not sometimes allocate and sometimes point at .data - test for LoadOptionSize == 0 and return success - print an error message for the failure so we can see it. Signed-off-by: Peter Jones Upstream-commit-id: 354bd9b1931 --- shim.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/shim.c b/shim.c index 2f7aba07421..5329795c333 100644 --- a/shim.c +++ b/shim.c @@ -2141,8 +2141,15 @@ EFI_STATUS set_second_stage (EFI_HANDLE image_handle) CHAR16 *loader_str = NULL; UINTN loader_len = 0; unsigned int i; + UINTN second_stage_len; - second_stage = DEFAULT_LOADER; + second_stage_len = StrLen(DEFAULT_LOADER) + 1; + second_stage = AllocatePool(second_stage_len); + if (!second_stage) { + perror(L"Could not allocate %lu bytes\n", second_stage_len); + return EFI_OUT_OF_RESOURCES; + } + StrCpy(second_stage, DEFAULT_LOADER); load_options = NULL; load_options_size = 0; @@ -2199,6 +2206,12 @@ EFI_STATUS set_second_stage (EFI_HANDLE image_handle) * BDS will add that, but we ignore that here. */ + /* + * Maybe there just aren't any options... + */ + if (li->LoadOptionsSize == 0) + return EFI_SUCCESS; + /* * In either case, we've got to have at least a UCS2 NUL... */ @@ -2465,7 +2478,11 @@ shim_init(void) dprint(L"%a", shim_version); /* Set the second stage loader */ - set_second_stage (global_image_handle); + efi_status = set_second_stage(global_image_handle); + if (EFI_ERROR(efi_status)) { + perror(L"set_second_stage() failed: %r\n", efi_status); + return efi_status; + } if (secure_mode()) { if (vendor_cert_size || vendor_dbx_size) { -- 2.26.2