]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-boot: Check for OOM in some places
authorJan Janssen <medhefgo@web.de>
Tue, 28 Sep 2021 08:21:42 +0000 (10:21 +0200)
committerJan Janssen <medhefgo@web.de>
Sun, 17 Oct 2021 09:52:36 +0000 (11:52 +0200)
src/boot/efi/boot.c
src/boot/efi/shim.c
src/boot/efi/stub.c
src/boot/efi/util.c

index 5fdf26240ad91dbf544c0370eefbc5a361b08f24..71e645a6080680062c654d1aad6b1a5c886ec15d 100644 (file)
@@ -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;
index 9fcc45403e591e54752a58c50395cae962b67112..404109784dad8afd8d26f6644872bb99056a02ce 100644 (file)
@@ -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))
index 01774d1fd53dd7d395bfc5a9ee9e02b4ab23279c..5b55323852caee0b8e2b184c744753e06d62675d 100644 (file)
@@ -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;
index 13697c9433dfd173b85c8a05f1be377bf217e162..7e6e41e4e873bdc528e6b8bf3538ac2973269934 100644 (file)
@@ -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;