[PATCH v2 1/1] In GRUB2 parser save_env, treat unset variable value as empty
Sam Mendoza-Jonas
sam at mendozajonas.com
Tue Mar 15 14:25:38 AEDT 2016
On Mon, Mar 14, 2016 at 05:40:47PM -0700, Alan Dunn wrote:
> It seems better to treat unset variable values as empty rather than
> crashing in save_env. While GRUB's behavior is actually to delete the
> variable from the environment block, it seems useful to at least not
> crash while later on someone can do further work to improve GRUB
> compatibility if desired.
>
> Tested:
> Modified test-grub2-save-env to cover this case.
>
> Signed-off-by: Alan Dunn <amdunn at google.com>
Thanks, merged as 6e5cd61
> ---
> discover/grub2/env.c | 4 ++++
> test/parser/test-grub2-save-env.c | 6 ++++++
> 2 files changed, 10 insertions(+)
>
> diff --git a/discover/grub2/env.c b/discover/grub2/env.c
> index 3598927..7eda095 100644
> --- a/discover/grub2/env.c
> +++ b/discover/grub2/env.c
> @@ -257,6 +257,10 @@ int builtin_save_env(struct grub2_script *script,
>
> name = argv[i];
> value = script_env_get(script, name);
> + if (!value) {
> + pb_log("Saved unset environment variable %s!\n", name);
> + value = "";
> + }
>
> update_env(buf + siglen, len - siglen, name, value);
> }
> diff --git a/test/parser/test-grub2-save-env.c b/test/parser/test-grub2-save-env.c
> index 68e91bd..36725e2 100644
> --- a/test/parser/test-grub2-save-env.c
> +++ b/test/parser/test-grub2-save-env.c
> @@ -74,6 +74,12 @@ struct env_test {
> "a=xxx\nsave_env a\n",
> "q=q\na=x\nr=r\n#",
> },
> + {
> + "unset-var",
> + "##############",
> + "save_env an_unset_var\n",
> + "an_unset_var=\n"
> + }
> };
>
> static void run_env_test(struct parser_test *test, struct env_test *envtest)
> --
> 2.7.0.rc3.207.g0ac5344
>
> _______________________________________________
> Petitboot mailing list
> Petitboot at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/petitboot
More information about the Petitboot
mailing list