mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-07 17:17:44 +03:00
sd-boot: Use non-failing allocators everywhere else
This commit is contained in:
parent
ccfbdbdcab
commit
0a15a824d2
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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),
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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];
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user