[PATCH 1/3] discover/grub2: Fix handling of positional parameters
Alan Dunn
amdunn at google.com
Thu Mar 3 03:59:02 AEDT 2016
Positional parameters are set in the environment with '$' prepended to
the name. This causes lookups to fail because parameter lookups don't
include the '$'.
TESTED:
Added a test that covers positional parameters in GRUB2 parser.
Build succeeds, tests pass.
Bootstrapped-by: Nancy Yuen <yuenn at google.com>
Signed-off-by: Alan Dunn <amdunn at google.com>
---
discover/grub2/script.c | 2 +-
test/parser/Makefile.am | 1 +
test/parser/test-grub2-pos-param.c | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 test/parser/test-grub2-pos-param.c
diff --git a/discover/grub2/script.c b/discover/grub2/script.c
index f521681..48c963e 100644
--- a/discover/grub2/script.c
+++ b/discover/grub2/script.c
@@ -380,7 +380,7 @@ static int function_invoke(struct grub2_script *script,
/* set positional parameters */
for (i = 0; i < argc; i++) {
- name = talloc_asprintf(script, "$%d", i);
+ name = talloc_asprintf(script, "%d", i);
script_env_set(script, name, argv[i]);
}
diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am
index dddb472..4bf9bc0 100644
--- a/test/parser/Makefile.am
+++ b/test/parser/Makefile.am
@@ -26,6 +26,7 @@ parser_TESTS = \
test/parser/test-grub2-multiple-resolve \
test/parser/test-grub2-multiple-id \
test/parser/test-grub2-single-line-if \
+ test/parser/test-grub2-pos-param \
test/parser/test-grub2-load-env \
test/parser/test-grub2-save-env \
test/parser/test-grub2-save-env-dash-f \
diff --git a/test/parser/test-grub2-pos-param.c b/test/parser/test-grub2-pos-param.c
new file mode 100644
index 0000000..09ac8fc
--- /dev/null
+++ b/test/parser/test-grub2-pos-param.c
@@ -0,0 +1,35 @@
+
+#include "parser-test.h"
+
+#if 0 /* PARSER_EMBEDDED_CONFIG */
+
+function set_params_var {
+ params="$1 $2"
+}
+menuentry 'Linux' {
+ set_params_var abc 123
+ linux test_kernel $params
+}
+
+#endif
+
+void run_test(struct parser_test *test)
+{
+ struct discover_boot_option *opt;
+ struct discover_context *ctx;
+
+ test_read_conf_embedded(test, "/boot/grub/grub.cfg");
+
+ test_run_parser(test, "grub2");
+
+ ctx = test->ctx;
+
+ check_boot_option_count(ctx, 1);
+ opt = get_boot_option(ctx, 0);
+
+ check_name(opt, "Linux");
+ /* The linux command, $params is expected to have been set when
+ * set_params was called in menuentry.
+ */
+ check_args(opt, "abc 123");
+}
--
2.7.0.rc3.207.g0ac5344
More information about the Petitboot
mailing list