summaryrefslogtreecommitdiffstats
path: root/src/boot/efi
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2021-11-17 11:11:23 +0100
committerJan Janssen <medhefgo@web.de>2021-11-29 16:20:45 +0100
commit0a15a824d2505f2a5657075c7ab888f28b39fc0a (patch)
treee7c69719582be9afc84a8e7c5666779e6d51dd3b /src/boot/efi
parentsd-boot: Simplify path creation (diff)
downloadsystemd-0a15a824d2505f2a5657075c7ab888f28b39fc0a.tar.xz
systemd-0a15a824d2505f2a5657075c7ab888f28b39fc0a.zip
sd-boot: Use non-failing allocators everywhere else
Diffstat (limited to 'src/boot/efi')
-rw-r--r--src/boot/efi/cpio.c33
-rw-r--r--src/boot/efi/drivers.c5
-rw-r--r--src/boot/efi/initrd.c6
-rw-r--r--src/boot/efi/linux.c6
-rw-r--r--src/boot/efi/measure.c10
-rw-r--r--src/boot/efi/pe.c2
-rw-r--r--src/boot/efi/random-seed.c12
-rw-r--r--src/boot/efi/splash.c6
-rw-r--r--src/boot/efi/stub.c20
-rw-r--r--src/boot/efi/util.c44
-rw-r--r--src/boot/efi/util.h2
-rw-r--r--src/boot/efi/xbootldr.c8
12 files changed, 35 insertions, 119 deletions
diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c
index 109003e9de..d7dd50fc8f 100644
--- a/src/boot/efi/cpio.c
+++ b/src/boot/efi/cpio.c
@@ -113,9 +113,7 @@ static EFI_STATUS pack_cpio_one(
if (*cpio_buffer_size > UINTN_MAX - l) /* overflow check */
return EFI_OUT_OF_RESOURCES;
- a = ReallocatePool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
- if (!a)
- return EFI_OUT_OF_RESOURCES;
+ a = xreallocate_pool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
*cpio_buffer = a;
a = (CHAR8*) *cpio_buffer + *cpio_buffer_size;
@@ -198,11 +196,8 @@ static EFI_STATUS pack_cpio_dir(
if (*cpio_buffer_size > UINTN_MAX - l) /* overflow check */
return EFI_OUT_OF_RESOURCES;
- a = ReallocatePool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
- if (!a)
- return EFI_OUT_OF_RESOURCES;
- *cpio_buffer = a;
+ *cpio_buffer = a = xreallocate_pool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
a = (CHAR8*) *cpio_buffer + *cpio_buffer_size;
CopyMem(a, "070701", 6); /* magic ID */
@@ -262,7 +257,7 @@ static EFI_STATUS pack_cpio_prefix(
if (e > p) {
_cleanup_freepool_ CHAR8 *t = NULL;
- t = strndup8(path, e - path);
+ t = xstrndup8(path, e - path);
if (!t)
return EFI_OUT_OF_RESOURCES;
@@ -298,19 +293,13 @@ static EFI_STATUS pack_cpio_trailer(
"00000000"
"TRAILER!!!\0\0\0"; /* There's a fourth NUL byte appended here, because this is a string */
- void *a;
-
/* Generates the cpio trailer record that indicates the end of our initrd cpio archive */
assert(cpio_buffer);
assert(cpio_buffer_size);
assert_cc(sizeof(trailer) % 4 == 0);
- a = ReallocatePool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + sizeof(trailer));
- if (!a)
- return EFI_OUT_OF_RESOURCES;
-
- *cpio_buffer = a;
+ *cpio_buffer = xreallocate_pool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + sizeof(trailer));
CopyMem((UINT8*) *cpio_buffer + *cpio_buffer_size, trailer, sizeof(trailer));
*cpio_buffer_size += sizeof(trailer);
@@ -346,10 +335,7 @@ EFI_STATUS pack_cpio(
if (!root)
return log_error_status_stall(EFI_LOAD_ERROR, L"Unable to open root directory.");
- extra_dir_path = PoolPrint(L"%D" EXTRA_DIR_SUFFIX, loaded_image->FilePath);
- if (!extra_dir_path)
- return log_oom();
-
+ extra_dir_path = xpool_print(L"%D" EXTRA_DIR_SUFFIX, loaded_image->FilePath);
err = open_directory(root, extra_dir_path, &extra_dir);
if (err == EFI_NOT_FOUND) {
/* No extra subdir, that's totally OK */
@@ -380,9 +366,7 @@ EFI_STATUS pack_cpio(
if (StrLen(dirent->FileName) > 255) /* Max filename size on Linux */
continue;
- d = StrDuplicate(dirent->FileName);
- if (!d)
- return log_oom();
+ d = xstrdup(dirent->FileName);
if (n_items+2 > n_allocated) {
UINTN m;
@@ -392,10 +376,7 @@ EFI_STATUS pack_cpio(
return log_oom();
m = n_items + 16;
- items = ReallocatePool(items, n_allocated * sizeof(UINT16*), m * sizeof(UINT16*));
- if (!items)
- return log_oom();
-
+ items = xreallocate_pool(items, n_allocated * sizeof(UINT16*), m * sizeof(UINT16*));
n_allocated = m;
}
diff --git a/src/boot/efi/drivers.c b/src/boot/efi/drivers.c
index 4bb4dedaa0..ce5cf3dcd7 100644
--- a/src/boot/efi/drivers.c
+++ b/src/boot/efi/drivers.c
@@ -25,10 +25,7 @@ static EFI_STATUS load_one_driver(
assert(loaded_image);
assert(fname);
- spath = PoolPrint(L"\\EFI\\systemd\\drivers\\%s", fname);
- if (!spath)
- return log_oom();
-
+ spath = xpool_print(L"\\EFI\\systemd\\drivers\\%s", fname);
path = FileDevicePath(loaded_image->DeviceHandle, spath);
if (!path)
return log_oom();
diff --git a/src/boot/efi/initrd.c b/src/boot/efi/initrd.c
index 4475a3d5ee..3136d3b8fa 100644
--- a/src/boot/efi/initrd.c
+++ b/src/boot/efi/initrd.c
@@ -6,6 +6,7 @@
#include "initrd.h"
#include "macro-fundamental.h"
#include "missing_efi.h"
+#include "util.h"
/* extend LoadFileProtocol */
struct initrd_loader {
@@ -88,10 +89,7 @@ EFI_STATUS initrd_register(
if (err != EFI_NOT_FOUND) /* InitrdMedia is already registered */
return EFI_ALREADY_STARTED;
- loader = AllocatePool(sizeof(struct initrd_loader));
- if (!loader)
- return EFI_OUT_OF_RESOURCES;
-
+ loader = xnew(struct initrd_loader, 1);
*loader = (struct initrd_loader) {
.load_file.LoadFile = initrd_load_file,
.address = initrd_address,
diff --git a/src/boot/efi/linux.c b/src/boot/efi/linux.c
index 8e3afb795b..ce0f4985c0 100644
--- a/src/boot/efi/linux.c
+++ b/src/boot/efi/linux.c
@@ -36,11 +36,7 @@ static EFI_STATUS loaded_image_register(
assert(ret_image);
/* create and install new LoadedImage Protocol */
- loaded_image = AllocatePool(sizeof(EFI_LOADED_IMAGE));
- if (!loaded_image)
- return EFI_OUT_OF_RESOURCES;
-
- /* provide the image base address and size */
+ loaded_image = xnew(EFI_LOADED_IMAGE, 1);
*loaded_image = (EFI_LOADED_IMAGE) {
.ImageBase = (void *) linux_buffer,
.ImageSize = linux_length
diff --git a/src/boot/efi/measure.c b/src/boot/efi/measure.c
index 220a8fbb35..4b6e8776ca 100644
--- a/src/boot/efi/measure.c
+++ b/src/boot/efi/measure.c
@@ -26,10 +26,7 @@ static EFI_STATUS tpm1_measure_to_pcr_and_event_log(
assert(description);
desc_len = StrSize(description);
- tcg_event = AllocateZeroPool(OFFSETOF(TCG_PCR_EVENT, Event) + desc_len);
- if (!tcg_event)
- return EFI_OUT_OF_RESOURCES;
-
+ tcg_event = xallocate_zero_pool(OFFSETOF(TCG_PCR_EVENT, Event) + desc_len);
*tcg_event = (TCG_PCR_EVENT) {
.EventSize = desc_len,
.PCRIndex = pcrindex,
@@ -60,10 +57,7 @@ static EFI_STATUS tpm2_measure_to_pcr_and_event_log(
assert(description);
desc_len = StrSize(description);
- tcg_event = AllocateZeroPool(OFFSETOF(EFI_TCG2_EVENT, Event) + desc_len);
- if (!tcg_event)
- return EFI_OUT_OF_RESOURCES;
-
+ tcg_event = xallocate_zero_pool(OFFSETOF(EFI_TCG2_EVENT, Event) + desc_len);
*tcg_event = (EFI_TCG2_EVENT) {
.Size = OFFSETOF(EFI_TCG2_EVENT, Event) + desc_len,
.Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER),
diff --git a/src/boot/efi/pe.c b/src/boot/efi/pe.c
index e87b720dfa..91e7529fb1 100644
--- a/src/boot/efi/pe.c
+++ b/src/boot/efi/pe.c
@@ -259,7 +259,7 @@ EFI_STATUS pe_file_locate_sections(
return EFI_LOAD_ERROR;
section_table_len = pe.FileHeader.NumberOfSections * sizeof(struct PeSectionHeader);
- section_table = AllocatePool(section_table_len);
+ section_table = xallocate_pool(section_table_len);
if (!section_table)
return EFI_OUT_OF_RESOURCES;
diff --git a/src/boot/efi/random-seed.c b/src/boot/efi/random-seed.c
index e829cf98b1..ecfd8a6b51 100644
--- a/src/boot/efi/random-seed.c
+++ b/src/boot/efi/random-seed.c
@@ -32,9 +32,7 @@ static EFI_STATUS acquire_rng(UINTN size, void **ret) {
if (!rng)
return EFI_UNSUPPORTED;
- data = AllocatePool(size);
- if (!data)
- return log_oom();
+ data = xallocate_pool(size);
err = rng->GetRNG(rng, NULL, size, data);
if (EFI_ERROR(err))
@@ -99,9 +97,7 @@ static EFI_STATUS hash_many(
/* Hashes the specified parameters in counter mode, generating n hash values, with the counter in the
* range counter_start…counter_start+n-1. */
- output = AllocatePool(n * HASH_VALUE_SIZE);
- if (!output)
- return log_oom();
+ output = xallocate_pool(n * HASH_VALUE_SIZE);
for (UINTN i = 0; i < n; i++)
hash_once(old_seed, rng, size,
@@ -274,9 +270,7 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
if (size > RANDOM_MAX_SIZE_MAX)
return log_error_status_stall(EFI_INVALID_PARAMETER, L"Random seed file is too large.");
- seed = AllocatePool(size);
- if (!seed)
- return log_oom();
+ seed = xallocate_pool(size);
rsize = size;
err = handle->Read(handle, &rsize, seed);
diff --git a/src/boot/efi/splash.c b/src/boot/efi/splash.c
index fa923e77f2..71bd008d96 100644
--- a/src/boot/efi/splash.c
+++ b/src/boot/efi/splash.c
@@ -260,7 +260,6 @@ EFI_STATUS graphics_splash(const UINT8 *content, UINTN len, const EFI_GRAPHICS_O
struct bmp_dib *dib;
struct bmp_map *map;
const UINT8 *pixmap;
- UINT64 blt_size;
_cleanup_freepool_ void *blt = NULL;
UINTN x_pos = 0;
UINTN y_pos = 0;
@@ -302,10 +301,7 @@ EFI_STATUS graphics_splash(const UINT8 *content, UINTN len, const EFI_GRAPHICS_O
return err;
/* EFI buffer */
- blt_size = sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * dib->x * dib->y;
- blt = AllocatePool(blt_size);
- if (!blt)
- return EFI_OUT_OF_RESOURCES;
+ blt = xnew(EFI_GRAPHICS_OUTPUT_BLT_PIXEL, dib->x * dib->y);
err = GraphicsOutput->Blt(
GraphicsOutput, blt,
diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c
index 4de23792b5..c99b3b7d6d 100644
--- a/src/boot/efi/stub.c
+++ b/src/boot/efi/stub.c
@@ -119,23 +119,15 @@ static void export_variables(EFI_LOADED_IMAGE *loaded_image) {
/* if LoaderFirmwareInfo is not set, let's set it */
if (efivar_get_raw(LOADER_GUID, L"LoaderFirmwareInfo", NULL, NULL) != EFI_SUCCESS) {
_cleanup_freepool_ CHAR16 *s = NULL;
-
- s = PoolPrint(L"%s %d.%02d", ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
- if (s)
- efivar_set(LOADER_GUID, L"LoaderFirmwareInfo", s, 0);
- else
- log_oom();
+ s = xpool_print(L"%s %d.%02d", ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
+ efivar_set(LOADER_GUID, L"LoaderFirmwareInfo", s, 0);
}
/* ditto for LoaderFirmwareType */
if (efivar_get_raw(LOADER_GUID, L"LoaderFirmwareType", NULL, NULL) != EFI_SUCCESS) {
_cleanup_freepool_ CHAR16 *s = NULL;
-
- s = PoolPrint(L"UEFI %d.%02d", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
- if (s)
- efivar_set(LOADER_GUID, L"LoaderFirmwareType", s, 0);
- else
- log_oom();
+ s = xpool_print(L"UEFI %d.%02d", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
+ efivar_set(LOADER_GUID, L"LoaderFirmwareType", s, 0);
}
/* add StubInfo */
@@ -206,9 +198,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
if ((!secure_boot_enabled() || cmdline_len == 0) && loaded_image->LoadOptionsSize > 0 &&
*(CHAR16 *) loaded_image->LoadOptions > 0x1F) {
cmdline_len = (loaded_image->LoadOptionsSize / sizeof(CHAR16)) * sizeof(CHAR8);
- cmdline = cmdline_owned = AllocatePool(cmdline_len);
- if (!cmdline)
- return log_oom();
+ cmdline = cmdline_owned = xallocate_pool(cmdline_len);
for (UINTN i = 0; i < cmdline_len; i++)
cmdline[i] = ((CHAR16 *) loaded_image->LoadOptions)[i];
diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c
index aa3c249562..04e390b0fa 100644
--- a/src/boot/efi/util.c
+++ b/src/boot/efi/util.c
@@ -180,9 +180,7 @@ EFI_STATUS efivar_get(const EFI_GUID *vendor, const CHAR16 *name, CHAR16 **value
}
/* Make sure a terminating NUL is available at the end */
- val = AllocatePool(size + sizeof(CHAR16));
- if (!val)
- return EFI_OUT_OF_RESOURCES;
+ val = xallocate_pool(size + sizeof(CHAR16));
CopyMem(val, buf, size);
val[size / sizeof(CHAR16)] = 0; /* NUL terminate */
@@ -256,9 +254,7 @@ EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const CHAR16 *name, CHAR8 **bu
assert(name);
l = sizeof(CHAR16 *) * EFI_MAXIMUM_VARIABLE_SIZE;
- buf = AllocatePool(l);
- if (!buf)
- return EFI_OUT_OF_RESOURCES;
+ buf = xallocate_pool(l);
err = RT->GetVariable((CHAR16 *) name, (EFI_GUID *) vendor, NULL, &l, buf);
if (!EFI_ERROR(err)) {
@@ -467,10 +463,7 @@ EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN s
return err;
}
- buf = AllocatePool(size + 1);
- if (!buf)
- return EFI_OUT_OF_RESOURCES;
-
+ buf = xallocate_pool(size + 1);
err = handle->Read(handle, &size, buf);
if (EFI_ERROR(err))
return err;
@@ -582,17 +575,11 @@ EFI_STATUS get_file_info_harder(
/* A lot like LibFileInfo() but with useful error propagation */
- fi = AllocatePool(size);
- if (!fi)
- return EFI_OUT_OF_RESOURCES;
-
+ fi = xallocate_pool(size);
err = handle->GetInfo(handle, &GenericFileInfo, &size, fi);
if (err == EFI_BUFFER_TOO_SMALL) {
FreePool(fi);
- fi = AllocatePool(size); /* GetInfo tells us the required size, let's use that now */
- if (!fi)
- return EFI_OUT_OF_RESOURCES;
-
+ fi = xallocate_pool(size); /* GetInfo tells us the required size, let's use that now */
err = handle->GetInfo(handle, &GenericFileInfo, &size, fi);
}
@@ -624,11 +611,7 @@ EFI_STATUS readdir_harder(
if (!*buffer) {
sz = OFFSETOF(EFI_FILE_INFO, FileName) /* + 256 */;
-
- *buffer = AllocatePool(sz);
- if (!*buffer)
- return EFI_OUT_OF_RESOURCES;
-
+ *buffer = xallocate_pool(sz);
*buffer_size = sz;
} else
sz = *buffer_size;
@@ -636,15 +619,8 @@ EFI_STATUS readdir_harder(
err = handle->Read(handle, &sz, *buffer);
if (err == EFI_BUFFER_TOO_SMALL) {
FreePool(*buffer);
-
- *buffer = AllocatePool(sz);
- if (!*buffer) {
- *buffer_size = 0;
- return EFI_OUT_OF_RESOURCES;
- }
-
+ *buffer = xallocate_pool(sz);
*buffer_size = sz;
-
err = handle->Read(handle, &sz, *buffer);
}
if (EFI_ERROR(err))
@@ -673,7 +649,7 @@ UINTN strnlena(const CHAR8 *p, UINTN maxlen) {
return c;
}
-CHAR8 *strndup8(const CHAR8 *p, UINTN sz) {
+CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz) {
CHAR8 *n;
/* Following efilib's naming scheme this function would be called strndupa(), but we already have a
@@ -684,9 +660,7 @@ CHAR8 *strndup8(const CHAR8 *p, UINTN sz) {
sz = strnlena(p, sz);
- n = AllocatePool(sz + 1);
- if (!n)
- return NULL;
+ n = xallocate_pool(sz + 1);
if (sz > 0)
CopyMem(n, p, sz);
diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h
index d5f32dbb38..425d25d73f 100644
--- a/src/boot/efi/util.h
+++ b/src/boot/efi/util.h
@@ -129,7 +129,7 @@ EFI_STATUS get_file_info_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **ret, UIN
EFI_STATUS readdir_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
UINTN strnlena(const CHAR8 *p, UINTN maxlen);
-CHAR8 *strndup8(const CHAR8 *p, UINTN sz);
+CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz);
BOOLEAN is_ascii(const CHAR16 *f);
diff --git a/src/boot/efi/xbootldr.c b/src/boot/efi/xbootldr.c
index 39c3c99d6e..81aa7f61ee 100644
--- a/src/boot/efi/xbootldr.c
+++ b/src/boot/efi/xbootldr.c
@@ -20,9 +20,7 @@ static EFI_DEVICE_PATH *path_parent(EFI_DEVICE_PATH *path, EFI_DEVICE_PATH *node
assert(node);
len = (UINT8*) NextDevicePathNode(node) - (UINT8*) path;
- parent = (EFI_DEVICE_PATH*) AllocatePool(len + sizeof(EFI_DEVICE_PATH));
- if (!parent)
- return NULL;
+ parent = (EFI_DEVICE_PATH*) xallocate_pool(len + sizeof(EFI_DEVICE_PATH));
CopyMem(parent, path, len);
CopyMem((UINT8*) parent + len, EndDevicePath, sizeof(EFI_DEVICE_PATH));
@@ -112,9 +110,7 @@ static EFI_STATUS try_gpt(
/* Now load the GPT entry table */
size = ALIGN_TO((UINTN) gpt.gpt_header.SizeOfPartitionEntry * (UINTN) gpt.gpt_header.NumberOfPartitionEntries, 512);
- entries = AllocatePool(size);
- if (!entries)
- return EFI_OUT_OF_RESOURCES;
+ entries = xallocate_pool(size);
err = block_io->ReadBlocks(
block_io,