]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/bootspec.c
Add fmemopen_unlocked() and use unlocked ops in fuzzers and some other tests
[thirdparty/systemd.git] / src / shared / bootspec.c
index af8da15236a9bcf799e0778dc2021a618ad97d39..b2f8936038bf529cc5564d376140ee25903812e3 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <stdio.h>
 #include <linux/magic.h>
+#include <unistd.h>
 
 #include "sd-device.h"
 #include "sd-id128.h"
@@ -27,6 +28,7 @@
 #include "string-util.h"
 #include "strv.h"
 #include "unaligned.h"
+#include "util.h"
 #include "virt.h"
 
 static void boot_entry_free(BootEntry *entry) {
@@ -158,6 +160,7 @@ void boot_config_free(BootConfig *config) {
         free(config->editor);
         free(config->auto_entries);
         free(config->auto_firmware);
+        free(config->console_mode);
 
         free(config->entry_oneshot);
         free(config->entry_default);
@@ -295,7 +298,7 @@ static int boot_entry_load_unified(
         if (!k)
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Path is not below root: %s", path);
 
-        f = fmemopen((void*) osrelease, strlen(osrelease), "r");
+        f = fmemopen_unlocked((void*) osrelease, strlen(osrelease), "r");
         if (!f)
                 return log_error_errno(errno, "Failed to open os-release buffer: %m");
 
@@ -733,7 +736,7 @@ int boot_entries_augment_from_loader(BootConfig *config, bool only_auto) {
                 "auto-reboot-to-firmware-setup", "Reboot Into Firmware Interface",
         };
 
-        _cleanup_free_ char **found_by_loader = NULL;
+        _cleanup_strv_free_ char **found_by_loader = NULL;
         size_t n_allocated;
         char **i;
         int r;
@@ -752,7 +755,7 @@ int boot_entries_augment_from_loader(BootConfig *config, bool only_auto) {
         n_allocated = config->n_entries;
 
         STRV_FOREACH(i, found_by_loader) {
-                _cleanup_free_ char *c = NULL, *t = NULL;
+                _cleanup_free_ char *c = NULL, *t = NULL, *p = NULL;
                 char **a, **b;
 
                 if (boot_config_has_entry(config, *i))
@@ -773,6 +776,10 @@ int boot_entries_augment_from_loader(BootConfig *config, bool only_auto) {
                                 break;
                         }
 
+                p = efi_variable_path(EFI_VENDOR_LOADER, "LoaderEntries");
+                if (!p)
+                        return log_oom();
+
                 if (!GREEDY_REALLOC0(config->entries, n_allocated, config->n_entries + 1))
                         return log_oom();
 
@@ -780,6 +787,7 @@ int boot_entries_augment_from_loader(BootConfig *config, bool only_auto) {
                         .type = BOOT_ENTRY_LOADER,
                         .id = TAKE_PTR(c),
                         .title = TAKE_PTR(t),
+                        .path = TAKE_PTR(p),
                 };
         }
 
@@ -1415,11 +1423,3 @@ found:
 
         return 0;
 }
-
-static const char* const boot_entry_type_table[_BOOT_ENTRY_MAX] = {
-        [BOOT_ENTRY_CONF] = "conf",
-        [BOOT_ENTRY_UNIFIED] = "unified",
-        [BOOT_ENTRY_LOADER] = "loader",
-};
-
-DEFINE_STRING_TABLE_LOOKUP(boot_entry_type, BootEntryType);