summaryrefslogtreecommitdiffstats
path: root/discover/grub2
diff options
context:
space:
mode:
authorAlan Dunn <amdunn@google.com>2016-01-12 15:43:02 -0800
committerSam Mendoza-Jonas <sam@mendozajonas.com>2016-02-08 15:27:41 +1100
commit01e104dfb79a09bc28f8c5fb65bfe44596c25161 (patch)
tree74d27b78669f4546537d105080bb20302dde6a2c /discover/grub2
parentb3d51f6ec5d077e6a2068fde0631074a7302b1da (diff)
downloadtalos-petitboot-01e104dfb79a09bc28f8c5fb65bfe44596c25161.tar.gz
talos-petitboot-01e104dfb79a09bc28f8c5fb65bfe44596c25161.zip
discover/grub2: Fix behavior of save_env -f
Currently, "save_env -f" in the GRUB2 parser only works with three arguments, which means only commands of the form "save_env -f <path>" that save *no* environment variables are allowed. Allow "save_env -f <path> [<var>]*", making "save_env -f" useful. Tested: Unit test test-grub2-save-env-dash-f tests this change, and the remaining unit tests still pass. Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'discover/grub2')
-rw-r--r--discover/grub2/env.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/discover/grub2/env.c b/discover/grub2/env.c
index 1336824..3598927 100644
--- a/discover/grub2/env.c
+++ b/discover/grub2/env.c
@@ -214,6 +214,7 @@ int builtin_save_env(struct grub2_script *script,
int i, rc, len, siglen;
char *buf, *envpath;
const char *envfile;
+ bool using_dash_f = false;
/* we only support local filesystems */
if (!dev->mounted) {
@@ -222,9 +223,15 @@ int builtin_save_env(struct grub2_script *script,
return -1;
}
- if (argc == 3 && !strcmp(argv[1], "-f"))
+ if (argc >= 2 && !strcmp(argv[1], "-f")) {
+ if (argc < 3) {
+ pb_log("save_env: for -f, need argument\n");
+ return -1;
+ }
+
envfile = argv[2];
- else
+ using_dash_f = true;
+ } else
envfile = default_envfile;
envpath = talloc_asprintf(script, "%s/%s",
@@ -241,7 +248,11 @@ int builtin_save_env(struct grub2_script *script,
if (rc || len < siglen || memcmp(buf, signature, siglen))
goto err;
- for (i = 1; i < argc; i++) {
+ /* For "-f", skip the "-f <file>" arguments in picking the
+ * variables to save. */
+ i = (using_dash_f ? 3 : 1);
+
+ for (; i < argc; i++) {
const char *name, *value;
name = argv[i];
OpenPOWER on IntegriCloud