]> git.ozlabs.org Git - petitboot/commitdiff
discover/grub: Fix handling of empty strings
authorSam Mendoza-Jonas <sam@mendozajonas.com>
Tue, 12 Jan 2016 04:58:13 +0000 (15:58 +1100)
committerSam Mendoza-Jonas <sam@mendozajonas.com>
Tue, 9 Feb 2016 02:39:50 +0000 (13:39 +1100)
If "" or '' are used in a statement to omit a word, we must still
return a TOKEN_WORD for an empty string.

In particular this fixes an issue where Petitboot would fail to parse
the grub.cfg included in the Debian 8.2 install image, which includes a
menuentry statement with an empty name.

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
discover/grub2/grub2-lexer.l
test/parser/test-grub2-menuentry-formats.c

index 52575e390713a3a6b1fe576a6fb0a76ae7abf0c0..81dc5fe8ac78678d883a8c8325ace472fe953fed 100644 (file)
@@ -23,6 +23,7 @@ void yyerror(struct grub2_parser *parser, const char *fmt, ...);
 
 WORD   [^{}|&$;<> \t\n'"#]+
 DELIM  [ \t]+
+BLANK  ["]{2}|[']{2}
 VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#])
 
 %%
@@ -52,6 +53,12 @@ VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#])
 "until"      return TOKEN_UTIL;
 "while"      return TOKEN_WHILE;
 
+ /* ignore quoted empty strings */
+{BLANK} {
+               yylval->word = create_word_text(yyget_extra(yyscanner), "");
+               yyget_extra(yyscanner)->inter_word = true;
+               return TOKEN_WORD;
+       }
  /* anything that's not a metachar: return as a plain word */
 {WORD} {
                yylval->word = create_word_text(yyget_extra(yyscanner), yytext);
index 132ce8d8ccf0c6abbdd28712921fb0ba7976b4e0..3c6f4d7fb9d3fd1954244d12cb301888afecda79 100644 (file)
@@ -20,6 +20,9 @@ menuentry "test.8" {
 menuentry "test.9" {
  linux /vmlinux
  }
+menuentry "" {
+ linux /vmlinux
+ }
 #endif
 
 void run_test(struct parser_test *test)
@@ -32,7 +35,7 @@ void run_test(struct parser_test *test)
 
        test_run_parser(test, "grub2");
 
-       check_boot_option_count(test->ctx, 10);
+       check_boot_option_count(test->ctx, 11);
        for (i = 0; i < 8; i++) {
                opt = get_boot_option(test->ctx, i);
                str[5] = i + '0';