]> git.ozlabs.org Git - petitboot/commitdiff
Allow evaluation of arbitrarily-positioned arguments in GRUB2 parser
authorAlan Dunn <amdunn@google.com>
Wed, 2 Mar 2016 16:59:03 +0000 (08:59 -0800)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 26 Apr 2016 02:56:36 +0000 (12:56 +1000)
GRUB2 allows essentially arbitrary numbers of positional arguments, so
ensure that they can be evaluated within scripts.  GRUB2 also appears
to support arbitrary numbers of leading 0's in positional parameters
(i.e., $01 should evalute the same as $1), but this doesn't seem like
a particularly important case to support.

Tested:
 Modified test-grub2-pos-param to cover higher-numbered positional
 arguments.

Signed-off-by: Alan Dunn <amdunn@google.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/grub2/grub2-lexer.l
test/parser/test-grub2-pos-param.c

index 81dc5fe8ac78678d883a8c8325ace472fe953fed..b55a71578a93413f1be1251bc3e680a9b9bc3097 100644 (file)
@@ -24,7 +24,8 @@ void yyerror(struct grub2_parser *parser, const char *fmt, ...);
 WORD   [^{}|&$;<> \t\n'"#]+
 DELIM  [ \t]+
 BLANK  ["]{2}|[']{2}
-VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#])
+NUMBER 0|[1-9][0-9]*
+VARNAME ([[:alpha:]][_[:alnum:]]*|{NUMBER}|[\?@\*#])
 
 %%
 
index 09ac8fc4558ba81ffc4f3bf74bcc6b9bf0c83b23..36447ff5d93baadc47731219959e010c4768c213 100644 (file)
@@ -4,10 +4,10 @@
 #if 0 /* PARSER_EMBEDDED_CONFIG */
 
 function set_params_var {
-       params="$1 $2"
+       params="$1 $2 $10"
 }
 menuentry 'Linux' {
-       set_params_var abc 123
+       set_params_var abc 123 3 4 5 6 7 8 9 bingo
        linux   test_kernel $params
 }
 
@@ -31,5 +31,5 @@ void run_test(struct parser_test *test)
        /* The linux command, $params is expected to have been set when
         * set_params was called in menuentry.
         */
-       check_args(opt, "abc 123");
+       check_args(opt, "abc 123 bingo");
 }