diff options
author | Jan Janssen <medhefgo@web.de> | 2021-09-28 10:21:42 +0200 |
---|---|---|
committer | Jan Janssen <medhefgo@web.de> | 2021-10-17 11:52:36 +0200 |
commit | 9f0481233110b521f945b341ebdf9d7ea9a4db3a (patch) | |
tree | 0a2ddc1cf538a8a32a8106243c1f2e6f346d9f1b | |
parent | e00324d092d6659bc0cb258c0d7043cde2e5a9ea (diff) | |
download | systemd-9f0481233110b521f945b341ebdf9d7ea9a4db3a.tar.gz |
sd-boot: Check for OOM in some places
-rw-r--r-- | src/boot/efi/boot.c | 25 | ||||
-rw-r--r-- | src/boot/efi/shim.c | 5 | ||||
-rw-r--r-- | src/boot/efi/stub.c | 18 | ||||
-rw-r--r-- | src/boot/efi/util.c | 4 |
4 files changed, 46 insertions, 6 deletions
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 5fdf26240a..71e645a608 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -127,11 +127,17 @@ static BOOLEAN line_edit( if (!line_in) line_in = L""; + size = StrLen(line_in) + 1024; line = AllocatePool(size * sizeof(CHAR16)); + if (!line) + return FALSE; + StrCpy(line, line_in); len = StrLen(line); print = AllocatePool((x_max+1) * sizeof(CHAR16)); + if (!print) + return FALSE; first = 0; cursor = 0; @@ -623,15 +629,25 @@ static BOOLEAN menu_run( /* Put status line after the entry list, but give it some breathing room. */ y_status = MIN(y_start + MIN(visible_max, config->entry_count) + 4, y_max - 1); - strv_free(lines); - FreePool(clearline); + lines = strv_free(lines); + clearline = mfree(clearline); /* menu entries title lines */ lines = AllocatePool((config->entry_count + 1) * sizeof(CHAR16 *)); + if (!lines) { + log_oom(); + return FALSE; + } + for (UINTN i = 0; i < config->entry_count; i++) { UINTN j, padding; lines[i] = AllocatePool(((line_width + 1) * sizeof(CHAR16))); + if (!lines[i]) { + log_oom(); + return FALSE; + } + padding = (line_width - MIN(StrLen(config->entries[i]->title_show), line_width)) / 2; for (j = 0; j < padding; j++) @@ -647,6 +663,11 @@ static BOOLEAN menu_run( lines[config->entry_count] = NULL; clearline = AllocatePool((x_max+1) * sizeof(CHAR16)); + if (!clearline) { + log_oom(); + return FALSE; + } + for (UINTN i = 0; i < x_max; i++) clearline[i] = ' '; clearline[x_max] = 0; diff --git a/src/boot/efi/shim.c b/src/boot/efi/shim.c index 9fcc45403e..404109784d 100644 --- a/src/boot/efi/shim.c +++ b/src/boot/efi/shim.c @@ -111,12 +111,13 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT UINTN file_size; assert(this); - assert(device_path_const); if (!device_path_const) return EFI_INVALID_PARAMETER; dev_path = DuplicateDevicePath((EFI_DEVICE_PATH*) device_path_const); + if (!dev_path) + return EFI_OUT_OF_RESOURCES; status = uefi_call_wrapper(BS->LocateDevicePath, 3, (EFI_GUID*) SIMPLE_FS_GUID, &dev_path, &h); if (status != EFI_SUCCESS) @@ -125,6 +126,8 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT /* No need to check return value, this already happened in efi_main() */ root = LibOpenRoot(h); dev_path_str = DevicePathToStr(dev_path); + if (!dev_path_str) + return EFI_OUT_OF_RESOURCES; status = file_read(root, dev_path_str, 0, 0, &file_buffer, &file_size); if (EFI_ERROR(status)) diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index 01774d1fd5..5b55323852 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -111,7 +111,10 @@ static VOID export_variables(EFI_LOADED_IMAGE *loaded_image) { _cleanup_freepool_ CHAR16 *s = NULL; s = DevicePathToStr(loaded_image->FilePath); - efivar_set(LOADER_GUID, L"LoaderImageIdentifier", s, 0); + if (s) + efivar_set(LOADER_GUID, L"LoaderImageIdentifier", s, 0); + else + log_oom(); } /* if LoaderFirmwareInfo is not set, let's set it */ @@ -119,7 +122,10 @@ static VOID export_variables(EFI_LOADED_IMAGE *loaded_image) { _cleanup_freepool_ CHAR16 *s = NULL; s = PoolPrint(L"%s %d.%02d", ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff); - efivar_set(LOADER_GUID, L"LoaderFirmwareInfo", s, 0); + if (s) + efivar_set(LOADER_GUID, L"LoaderFirmwareInfo", s, 0); + else + log_oom(); } /* ditto for LoaderFirmwareType */ @@ -127,7 +133,10 @@ static VOID export_variables(EFI_LOADED_IMAGE *loaded_image) { _cleanup_freepool_ CHAR16 *s = NULL; s = PoolPrint(L"UEFI %d.%02d", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff); - efivar_set(LOADER_GUID, L"LoaderFirmwareType", s, 0); + if (s) + efivar_set(LOADER_GUID, L"LoaderFirmwareType", s, 0); + else + log_oom(); } /* add StubInfo */ @@ -194,6 +203,9 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { options = (CHAR16 *)loaded_image->LoadOptions; cmdline_len = (loaded_image->LoadOptionsSize / sizeof(CHAR16)) * sizeof(CHAR8); line = AllocatePool(cmdline_len); + if (!line) + return log_oom(); + for (UINTN i = 0; i < cmdline_len; i++) line[i] = options[i]; cmdline = line; diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 13697c9433..7e6e41e4e8 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -368,6 +368,8 @@ CHAR16 *stra_to_str(const CHAR8 *stra) { len = strlena(stra); str = AllocatePool((len + 1) * sizeof(CHAR16)); + if (!str) + return NULL; strlen = 0; i = 0; @@ -398,6 +400,8 @@ CHAR16 *stra_to_path(const CHAR8 *stra) { len = strlena(stra); str = AllocatePool((len + 2) * sizeof(CHAR16)); + if (!str) + return NULL; str[0] = '\\'; strlen = 1; |