]> git.ozlabs.org Git - petitboot/commitdiff
discover/grub2: strdup strings used in the environment
authorJeremy Kerr <jk@ozlabs.org>
Tue, 1 Oct 2013 04:42:57 +0000 (12:42 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 1 Oct 2013 04:52:00 +0000 (12:52 +0800)
Use a copy of the name & value pairs that we pass to the environment, as
the data loaded from load_env will be talloc_free-ed.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/grub2/script.c

index 75b8aaaae474fc6348215dea26d7e963f31e4562..2aaf1d3d2cb1495a63c48fe7d31f72882d921b52 100644 (file)
@@ -23,8 +23,8 @@
        container_of(stmt, struct grub2_statement_conditional, st)
 
 struct env_entry {
-       const char              *name;
-       const char              *value;
+       char                    *name;
+       char                    *value;
        struct list_item        list;
 };
 
@@ -75,11 +75,13 @@ void script_env_set(struct grub2_script *script,
 
        if (!entry) {
                entry = talloc(script, struct env_entry);
-               entry->name = name;
+               entry->name = talloc_strdup(entry, name);
                list_add(&script->environment, &entry->list);
+       } else {
+               talloc_free(entry->value);
        }
 
-       entry->value = value;
+       entry->value = talloc_strdup(entry, value);
 }
 
 static bool expand_var(struct grub2_script *script, struct grub2_word *word)