sd-boot: Check for OOM in some places
This commit is contained in:
+23
-2
@@ -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;
|
||||
|
||||
+4
-1
@@ -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))
|
||||
|
||||
+15
-3
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user