:: commit 79e4a2c4e75700ebf790ee6e93013ccaa1716748

mintsuki <mintsuki@protonmail.com> — 2022-03-02 12:31

parents: 39ff8ad841

misc: Ensure editor is not accessible from console if disabled

diff --git a/common/console.c b/common/console.c
index 8823f106..ae3c5941 100644
--- a/common/console.c
+++ b/common/console.c
@@ -15,10 +15,11 @@ static void console_help(void) {
         "Available commands:\n"
         "exit      -- Exit Limine console.\n"
         "clear     -- Clears the console.\n"
-        "editor    -- Open an empty boot entry editor.\n"
+        "%s"
         "version   -- Print version.\n"
         "copyright -- Print copyright.\n"
-        "help      -- Print this help message.\n"
+        "help      -- Print this help message.\n",
+        editor_enabled ? "editor    -- Open an empty boot entry editor.\n" : ""
     );
 }
 
@@ -37,7 +38,7 @@ void console(void) {
             break;
         } else if (strcmp(prompt, "clear") == 0) {
             print("\e[2J\e[H");
-        } else if (strcmp(prompt, "editor") == 0) {
+        } else if (editor_enabled && strcmp(prompt, "editor") == 0) {
             char *new_entry = config_entry_editor("New Entry", "");
             if (new_entry != NULL) {
                 boot(new_entry);
diff --git a/common/lib/blib.c b/common/lib/blib.c
index 175c5f97..a0421ea6 100644
--- a/common/lib/blib.c
+++ b/common/lib/blib.c
@@ -19,6 +19,8 @@ UINTN efi_mmap_size = 0, efi_desc_size = 0;
 UINT32 efi_desc_ver = 0;
 #endif
 
+bool editor_enabled = true;
+
 bool parse_resolution(size_t *width, size_t *height, size_t *bpp, const char *buf) {
     size_t res[3] = {0};
 
diff --git a/common/lib/blib.h b/common/lib/blib.h
index da84fb21..fe278107 100644
--- a/common/lib/blib.h
+++ b/common/lib/blib.h
@@ -33,7 +33,7 @@ extern struct volume *boot_volume;
 extern bool stage3_loaded;
 #endif
 
-extern bool verbose, quiet, serial;
+extern bool verbose, quiet, serial, editor_enabled;
 
 bool parse_resolution(size_t *width, size_t *height, size_t *bpp, const char *buf);
 
diff --git a/common/menu.c b/common/menu.c
index 550a83a1..77900393 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -665,6 +665,11 @@ static noreturn void _menu(bool timeout_enabled) {
     char *serial_str = config_get_value(NULL, 0, "SERIAL");
     serial = serial_str != NULL && strcmp(serial_str, "yes") == 0;
 
+    char *editor_enabled_str = config_get_value(NULL, 0, "EDITOR_ENABLED");
+    if (editor_enabled_str != NULL) {
+        editor_enabled = strcmp(editor_enabled_str, "yes") == 0;
+    }
+
     menu_branding = config_get_value(NULL, 0, "MENU_BRANDING");
     if (menu_branding == NULL)
         menu_branding = "Limine " LIMINE_VERSION;
@@ -699,10 +704,6 @@ static noreturn void _menu(bool timeout_enabled) {
         skip_timeout = true;
     }
 
-    bool editor_enabled = true;
-    char *editor_enabled_config = config_get_value(NULL, 0, "EDITOR_ENABLED");
-    if (!strcmp(editor_enabled_config, "no")) editor_enabled = false;
-
     if (!skip_timeout && !timeout) {
         // Use print tree to load up selected_menu_entry and determine if the
         // default entry is valid.
tab: 248 wrap: offon