summaryrefslogtreecommitdiffstats
path: root/discover/grub2/script.c
diff options
context:
space:
mode:
Diffstat (limited to 'discover/grub2/script.c')
-rw-r--r--discover/grub2/script.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/discover/grub2/script.c b/discover/grub2/script.c
index 1a802b9..14931f9 100644
--- a/discover/grub2/script.c
+++ b/discover/grub2/script.c
@@ -117,12 +117,10 @@ static bool option_is_default(struct grub2_script *script,
if (end != var && *end == '\0')
return default_idx == script->n_options;
- /* if we don't have an explicit id for this option, fall back to
- * the name */
- if (!id)
- id = opt->option->name;
+ if (id && !strcmp(id, var))
+ return true;
- return !strcmp(id, var);
+ return !strcmp(opt->option->name, var);
}
static void append_text_to_current_arg(struct grub2_argv *argv,
@@ -227,11 +225,11 @@ static void process_expansions(struct grub2_script *script,
}
/* we may have allocated an extra argv element but not populated it */
- if (!argv->argv[argv->argc - 1])
+ if (argv->argv && !argv->argv[argv->argc - 1])
argv->argc--;
}
-static int statements_execute(struct grub2_script *script,
+int statements_execute(struct grub2_script *script,
struct grub2_statements *stmts)
{
struct grub2_statement *stmt;
@@ -341,9 +339,16 @@ int statement_menuentry_execute(struct grub2_script *script,
* implementation to get --id= working.
*/
for (i = 1; i < st->argv->argc; ++i) {
- if (strncmp("--id=", st->argv->argv[i], 5) == 0) {
- id = st->argv->argv[i] + 5;
- break;
+ if (strncmp("--id", st->argv->argv[i], strlen("--id")) == 0) {
+ if (strlen(st->argv->argv[i]) > strlen("--id=")) {
+ id = st->argv->argv[i] + strlen("--id=");
+ break;
+ }
+
+ if (i + 1 < st->argv->argc) {
+ id = st->argv->argv[i + 1];
+ break;
+ }
}
}
if (st->argv->argc > 0)
@@ -489,6 +494,9 @@ void script_execute(struct grub2_script *script)
{
struct discover_boot_option *opt, *tmp;
+ if (!script)
+ return;
+
init_env(script);
statements_execute(script, script->statements);
@@ -510,6 +518,7 @@ struct grub2_script *create_script(struct grub2_parser *parser,
script = talloc_zero(parser, struct grub2_script);
script->ctx = ctx;
+ script->parser = parser;
list_init(&script->symtab);
list_init(&script->options);
OpenPOWER on IntegriCloud