From: Masami Hiramatsu (Google) <[email protected]>

Fix bootconfig to terminate the value search if it hits a newline
even if it is empty.

When we pass a bootconfig with an empty value terminated by the
newline, like below::

  foo =
  bar = value

Current bootconfig interprets it as a single entry::

  foo = "bar = value";

However, the Documentation/admin-guide/bootconfig.rst said that

  The value has to be terminated by semi-colon (``;``) or newline (``\n``).

Thus, it should be interpreted as::

  foo = "";
  bar = "value";

Note that if the line has a comment, it still keep searching the
value to the next line::

  foo = # comment
  value

This is interpreted as `foo = "value"`.
This also updates the test script so that it can check the above cases.

Fixes: 76db5a27a827 ("bootconfig: Add Extra Boot Config support")
Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
---
 tools/bootconfig/test-bootconfig.sh |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index 81f29c29f47b..94b55ec32444 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -563,7 +563,7 @@ static int __init __xbc_parse_value(char **__v, char **__n)
        char *p, *v = *__v;
        int c, quotes = 0;
 
-       v = skip_spaces(v);
+       v = skip_spaces_until_newline(v);
        while (*v == '#') {
                v = skip_comment(v);
                v = skip_spaces(v);
diff --git a/tools/bootconfig/test-bootconfig.sh 
b/tools/bootconfig/test-bootconfig.sh
index 7594659af1e1..0873883182b0 100755
--- a/tools/bootconfig/test-bootconfig.sh
+++ b/tools/bootconfig/test-bootconfig.sh
@@ -171,6 +171,24 @@ $BOOTCONF $INITRD > $OUTFILE
 xfail grep -q 'val[[:space:]]' $OUTFILE
 xpass grep -q 'val2[[:space:]]' $OUTFILE
 
+echo "Empty value with ="
+cat > $TEMPCONF << EOF
+foo =
+bar
+EOF
+$BOOTCONF $TEMPCONF > $OUTFILE
+xfail grep 'foo[[:space:]]=[[:space:]]"bar"' $OUTFILE
+xpass grep 'foo[[:space:]]=[[:space:]]"";' $OUTFILE
+
+echo "Continue value after comment"
+cat > $TEMPCONF << EOF
+foo = # comment
+bar
+EOF
+$BOOTCONF $TEMPCONF > $OUTFILE
+xpass grep 'foo[[:space:]]=[[:space:]]"bar"' $OUTFILE
+xfail grep 'foo[[:space:]]=[[:space:]]"";' $OUTFILE
+
 echo "=== expected failure cases ==="
 for i in samples/bad-* ; do
   xfail $BOOTCONF -a $i $INITRD


Reply via email to