bootconfig: Fix to terminate value search if it hits a newline
Subsystems (3)
Masami Hiramatsu (Google)
maintainerPATCH 1/1 bootconfig: Fix to terminate value search if it hits a newline
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.
--- tools/bootconfig/test-bootconfig.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
lib/bootconfig.c +1 -1
@@ -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);
tools/bootconfig/test-bootconfig.sh +18 -0
@@ -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
Quoted 5 lines · On Fri, 30 Jan 2026 13:41:45 +0900 "Masami Hiramatsu (Google)"…
Note that if the line has a comment, it still keep searching the value to the next line::
foo = # comment
value
Hmm, so the above is the same as: foo = "value";
But what is:
foo = value # comment
bar
?
Would that be foo = value bar;
Or simply an error. Or would both be an error?
OK, this isn't related to the patch, but as comment processing was brought to my attention, I'm wondering how it works for the above.
Quoted 9 lines
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(+)
As for the patch itself:
-- Steve
Quoted 5 lines
Quoted 5 lines
Note that if the line has a comment, it still keep searching the value to the next line::
foo = # comment
value
This seems inconsistent to me tbh. I think someone could reasonably write a bootconfig like this:
foo = # We leave foo empty here because <reason>
bar = value
and expect it to work. There's nothing in the documentation that suggests empty values would behave differently if there is a comment behind them.
Also, I believe your patch might inadvertently break this case (which I think(?) is supposed to work):
foo = first array value,
second array value,
third array value
Because __xbc_parse_value() returns from the first value with &next pointing at the newline behind the comma, and that is passed to the next iteration of __xbc_parse_value() which will now no longer skip it. I think an already started array may need to be treated as a special case here and you may want to add another skip_spaces()/skip_comment() to the loop in xbc_parse_array().
Masami Hiramatsu (Google)
maintainerQuoted 9 lines · On Fri, 30 Jan 2026 15:26:46 -0800 Julius Werner <[email protected]> wrote:
Quoted 5 lines
Quoted 5 lines
Note that if the line has a comment, it still keep searching the value to the next line::
foo = # comment
valueThis seems inconsistent to me tbh. I think someone could reasonably write a bootconfig like this:
Quoted 6 lines
foo = # We leave foo empty here because <reason>
bar = valueand expect it to work. There's nothing in the documentation that suggests empty values would behave differently if there is a comment behind them.
But we already accept that example in the tree.
tools/bootconfig/samples/good-array-space-comment.bconf
So it is hard to change this syntax. But without comment, the document defines the value is terminated with a newline. Thus it needs to be fixed.
Quoted 7 lines
Also, I believe your patch might inadvertently break this case (which I think(?) is supposed to work):
foo = first array value,
second array value,
third array value
Oops, good catch! I should add this as a good sample.
Quoted 7 lines
Because
__xbc_parse_value()returns from the first value with&nextpointing at the newline behind the comma, and that is passed to the next iteration of__xbc_parse_value()which will now no longer skip it. I think an already started array may need to be treated as a special case here and you may want to add another skip_spaces()/skip_comment() to the loop inxbc_parse_array().
OK, let me fix it.
Thanks,
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Quoted 10 lines
Quoted 9 lines
This seems inconsistent to me tbh. I think someone could reasonably write a bootconfig like this:
foo = # We leave foo empty here because <reason>
bar = valueand expect it to work. There's nothing in the documentation that suggests empty values would behave differently if there is a comment behind them.
Quoted 7 lines
But we already accept that example in the tree.
tools/bootconfig/samples/good-array-space-comment.bconfSo it is hard to change this syntax. But without comment, the document defines the value is terminated with a newline. Thus it needs to be fixed.
Hmm... okay. I think it would be good to add an example like this (without array) to admin-guide/bootconfig.rst. It isn't very clear to me that the comment "negates" the following newline in the way it is written right now.