|
|
3b98a7 |
From ccebad103f3466d5e8fc2b60f6127af618adf8d2 Mon Sep 17 00:00:00 2001
|
|
|
3b98a7 |
From: David Lutterkort <lutter@watzmann.net>
|
|
|
3b98a7 |
Date: Mon, 4 Jun 2018 10:45:19 -0700
|
|
|
3b98a7 |
Subject: [PATCH] Grub: tolerate some invalid entries
|
|
|
3b98a7 |
|
|
|
3b98a7 |
Refusing to parse an entire file because of invalid entries is too
|
|
|
3b98a7 |
harsh. Try to make the behavior a little friendlier by simply mapping invalid
|
|
|
3b98a7 |
entries to '#error' nodes but still parsing the rest of the file.
|
|
|
3b98a7 |
|
|
|
3b98a7 |
Also remove del_to_eol, that would delete anything up to eol; it was only
|
|
|
3b98a7 |
used in kw_pres, but should have never been used there. kw_pres should only
|
|
|
3b98a7 |
match the keyword and eol. A line like 'quiet foo bar baz' should not be
|
|
|
3b98a7 |
accepted by (kw_pres "quiet").
|
|
|
3b98a7 |
---
|
|
|
3b98a7 |
lenses/grub.aug | 58 ++++++++++++++++++++++++++++++++------
|
|
|
3b98a7 |
lenses/tests/test_grub.aug | 25 ++++++++++++++++
|
|
|
3b98a7 |
2 files changed, 75 insertions(+), 8 deletions(-)
|
|
|
3b98a7 |
|
|
|
3b98a7 |
diff --git a/lenses/grub.aug b/lenses/grub.aug
|
|
|
3b98a7 |
index 9866f3f7..f99a3a92 100644
|
|
|
3b98a7 |
--- a/lenses/grub.aug
|
|
|
3b98a7 |
+++ b/lenses/grub.aug
|
|
|
3b98a7 |
@@ -29,9 +29,6 @@ module Grub =
|
|
|
3b98a7 |
(* View: eol *)
|
|
|
3b98a7 |
let eol = Util.eol
|
|
|
3b98a7 |
|
|
|
3b98a7 |
- (* View: del_to_eol *)
|
|
|
3b98a7 |
- let del_to_eol = del /[^ \t\n]*/ ""
|
|
|
3b98a7 |
-
|
|
|
3b98a7 |
(* View: spc *)
|
|
|
3b98a7 |
let spc = Util.del_ws_spc
|
|
|
3b98a7 |
|
|
|
3b98a7 |
@@ -92,7 +89,22 @@ module Grub =
|
|
|
3b98a7 |
eol ]
|
|
|
3b98a7 |
|
|
|
3b98a7 |
(* View: kw_pres *)
|
|
|
3b98a7 |
- let kw_pres (kw:string) = [ opt_ws . key kw . del_to_eol . eol ]
|
|
|
3b98a7 |
+ let kw_pres (kw:string) = [ opt_ws . key kw . eol ]
|
|
|
3b98a7 |
+
|
|
|
3b98a7 |
+ (* View: error
|
|
|
3b98a7 |
+ * Parse a line that looks almost like a valid setting, but isn't,
|
|
|
3b98a7 |
+ * into an '#error' node. Any line that starts with letters, but not
|
|
|
3b98a7 |
+ * anything matching kw, is considered an error line.
|
|
|
3b98a7 |
+ *
|
|
|
3b98a7 |
+ * Parameters:
|
|
|
3b98a7 |
+ * kw:regexp - the valid keywords that are _not_ considered an
|
|
|
3b98a7 |
+ * error
|
|
|
3b98a7 |
+ *)
|
|
|
3b98a7 |
+ let error (kw:regexp) =
|
|
|
3b98a7 |
+ let not_kw = /[a-zA-Z]+/ - kw in
|
|
|
3b98a7 |
+ [ label "#error" . Util.del_opt_ws "\t"
|
|
|
3b98a7 |
+ . store (not_kw . /([^a-zA-Z\n].*[^ \t\n])?/) . eol ]
|
|
|
3b98a7 |
+
|
|
|
3b98a7 |
|
|
|
3b98a7 |
(************************************************************************
|
|
|
3b98a7 |
* Group: BOOT ENTRIES
|
|
|
3b98a7 |
@@ -138,8 +150,8 @@ module Grub =
|
|
|
3b98a7 |
spc . [ label "from" . store Rx.no_spaces ] )? .
|
|
|
3b98a7 |
eol ]
|
|
|
3b98a7 |
|
|
|
3b98a7 |
- (* View: menu_setting *)
|
|
|
3b98a7 |
- let menu_setting = kw_menu_arg "default"
|
|
|
3b98a7 |
+ (* View: menu_entry *)
|
|
|
3b98a7 |
+ let menu_entry = kw_menu_arg "default"
|
|
|
3b98a7 |
| kw_menu_arg "fallback"
|
|
|
3b98a7 |
| kw_pres "hiddenmenu"
|
|
|
3b98a7 |
| kw_menu_arg "timeout"
|
|
|
3b98a7 |
@@ -156,6 +168,21 @@ module Grub =
|
|
|
3b98a7 |
| device
|
|
|
3b98a7 |
| setkey
|
|
|
3b98a7 |
|
|
|
3b98a7 |
+ (* View: menu_error
|
|
|
3b98a7 |
+ * Accept lines not matching menu_entry and stuff them into
|
|
|
3b98a7 |
+ * '#error' nodes
|
|
|
3b98a7 |
+ *)
|
|
|
3b98a7 |
+ let menu_error =
|
|
|
3b98a7 |
+ let kw = /default|fallback|hiddenmenu|timeout|splashimage|gfxmenu/
|
|
|
3b98a7 |
+ |/foreground|background|verbose|boot|password|title/
|
|
|
3b98a7 |
+ |/serial|setkey|terminal|color|device/ in
|
|
|
3b98a7 |
+ error kw
|
|
|
3b98a7 |
+
|
|
|
3b98a7 |
+ (* View: menu_setting
|
|
|
3b98a7 |
+ * a valid menu setting or a line that looks like one but is an #error
|
|
|
3b98a7 |
+ *)
|
|
|
3b98a7 |
+ let menu_setting = menu_entry | menu_error
|
|
|
3b98a7 |
+
|
|
|
3b98a7 |
(* View: title *)
|
|
|
3b98a7 |
let title = del /title[ \t=]+/ "title " . value_to_eol . eol
|
|
|
3b98a7 |
|
|
|
3b98a7 |
@@ -206,9 +233,9 @@ module Grub =
|
|
|
3b98a7 |
let configfile =
|
|
|
3b98a7 |
[ command "configfile" "\t" . spc . store Rx.no_spaces . eol ]
|
|
|
3b98a7 |
|
|
|
3b98a7 |
- (* View: boot_setting
|
|
|
3b98a7 |
+ (* View: boot_entry
|
|
|
3b98a7 |
<boot> entries *)
|
|
|
3b98a7 |
- let boot_setting =
|
|
|
3b98a7 |
+ let boot_entry =
|
|
|
3b98a7 |
let boot_arg_re = "root" | "initrd" | "rootnoverify" | "uuid"
|
|
|
3b98a7 |
| "findroot" | "bootfs" (* Solaris extensions *)
|
|
|
3b98a7 |
in kw_boot_arg boot_arg_re
|
|
|
3b98a7 |
@@ -223,6 +250,21 @@ module Grub =
|
|
|
3b98a7 |
| kw_pres "makeactive"
|
|
|
3b98a7 |
| password_arg
|
|
|
3b98a7 |
|
|
|
3b98a7 |
+ (* View: boot_error
|
|
|
3b98a7 |
+ * Accept lines not matching boot_entry and stuff them into
|
|
|
3b98a7 |
+ * '#error' nodes
|
|
|
3b98a7 |
+ *)
|
|
|
3b98a7 |
+ let boot_error =
|
|
|
3b98a7 |
+ let kw = /lock|uuid|password|root|initrd|rootnoverify|findroot|bootfs/
|
|
|
3b98a7 |
+ |/configfile|chainloader|title|boot|quiet|kernel|module/
|
|
|
3b98a7 |
+ |/makeactive|savedefault|map/ in
|
|
|
3b98a7 |
+ error kw
|
|
|
3b98a7 |
+
|
|
|
3b98a7 |
+ (* View: boot_setting
|
|
|
3b98a7 |
+ * a valid boot setting or a line that looks like one but is an #error
|
|
|
3b98a7 |
+ *)
|
|
|
3b98a7 |
+ let boot_setting = boot_entry | boot_error
|
|
|
3b98a7 |
+
|
|
|
3b98a7 |
(* View: boot *)
|
|
|
3b98a7 |
let boot =
|
|
|
3b98a7 |
let line = ((boot_setting|comment)* . boot_setting)? in
|
|
|
3b98a7 |
diff --git a/lenses/tests/test_grub.aug b/lenses/tests/test_grub.aug
|
|
|
3b98a7 |
index 8a0d9f4a..75657203 100644
|
|
|
3b98a7 |
--- a/lenses/tests/test_grub.aug
|
|
|
3b98a7 |
+++ b/lenses/tests/test_grub.aug
|
|
|
3b98a7 |
@@ -257,3 +257,28 @@ password --encrypted ^9^32kwzzX./3WISQ0C /boot/grub/custom.lst
|
|
|
3b98a7 |
{ "password" = "secret"
|
|
|
3b98a7 |
{ "md5" }
|
|
|
3b98a7 |
} }
|
|
|
3b98a7 |
+
|
|
|
3b98a7 |
+ (* Test parsing of invalid entries via menu_error *)
|
|
|
3b98a7 |
+ test Grub.lns get "default=0\ncrud=no\n" =
|
|
|
3b98a7 |
+ { "default" = "0" }
|
|
|
3b98a7 |
+ { "#error" = "crud=no" }
|
|
|
3b98a7 |
+
|
|
|
3b98a7 |
+ (* We handle some pretty bizarre bad syntax *)
|
|
|
3b98a7 |
+ test Grub.lns get "default=0
|
|
|
3b98a7 |
+crud no
|
|
|
3b98a7 |
+valid:nope
|
|
|
3b98a7 |
+nonsense = yes
|
|
|
3b98a7 |
+bad arg1 arg2 arg3=v\n" =
|
|
|
3b98a7 |
+ { "default" = "0" }
|
|
|
3b98a7 |
+ { "#error" = "crud no" }
|
|
|
3b98a7 |
+ { "#error" = "valid:nope" }
|
|
|
3b98a7 |
+ { "#error" = "nonsense = yes" }
|
|
|
3b98a7 |
+ { "#error" = "bad arg1 arg2 arg3=v" }
|
|
|
3b98a7 |
+
|
|
|
3b98a7 |
+ (* Test parsing of invalid entries via boot_error *)
|
|
|
3b98a7 |
+ test Grub.lns get "title test
|
|
|
3b98a7 |
+ root (hd0,0)
|
|
|
3b98a7 |
+ crud foo\n" =
|
|
|
3b98a7 |
+ { "title" = "test"
|
|
|
3b98a7 |
+ { "root" = "(hd0,0)" }
|
|
|
3b98a7 |
+ { "#error" = "crud foo" } }
|
|
|
3b98a7 |
--
|
|
|
c941cc |
2.24.1
|
|
|
3b98a7 |
|