bootconfig: Trim unquoted values at end of file

__xbc_parse_value() trims an unquoted value when it encounters a
delimiter, but leaves trailing whitespace intact when it reaches the end
of the input. Thus "key = value   " has a different value depending on
whether the file ends with a newline. The extra whitespace also reaches
the rendered kernel command line.

Trim unquoted values after the scan finishes, including at end of input.
Skip trimming after a closing quote so intentional whitespace in quoted
values remains unchanged. Add checks for scalars, arrays and quoted
values without a final newline.

Link: https://lore.kernel.org/all/31f248f330e716b925add3a0ba76f62826527312.1794337724.git.edumucelli@gmail.com/

Fixes: 76db5a27a8 ("bootconfig: Add Extra Boot Config support")
Cc: [email protected]
Signed-off-by: Eduardo Mucelli Rezende Oliveira <[email protected]>
Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
This commit is contained in:
Eduardo Mucelli Rezende Oliveira
2026-11-13 14:15:27 +09:00
committed by Masami Hiramatsu (Google)
parent 26fa92f351
commit 381b391bfa
2 changed files with 21 additions and 2 deletions
+3 -2
View File
@@ -793,16 +793,17 @@ static int __init __xbc_parse_value(char **__v, char **__n)
return xbc_parse_error("No value delimiter", p);
if (*p)
p++;
break;
goto skip_trim;
}
if (strchr(",;\n#}", c)) {
*p++ = '\0';
v = strim(v);
break;
}
}
if (quotes)
return xbc_parse_error("No closing quotes", p);
v = strim(v);
skip_trim:
if (c == '#') {
p = skip_comment(p);
c = '\n'; /* A comment must be treated as a newline */
+18
View File
@@ -181,6 +181,24 @@ $BOOTCONF $INITRD > $OUTFILE
xfail grep -q 'val[[:space:]]' $OUTFILE
xpass grep -q 'val2[[:space:]]' $OUTFILE
echo "Remove unquoted trailing whitespace at end of file"
printf 'foo = val \t' > $TEMPCONF
$BOOTCONF -l $TEMPCONF > $OUTFILE
printf 'foo = "val"\n' > $TEMPCONF
xpass cmp $TEMPCONF $OUTFILE
echo "Remove trailing whitespace from the last array value at end of file"
printf 'foo = first, last \t' > $TEMPCONF
$BOOTCONF -l $TEMPCONF > $OUTFILE
printf 'foo = "first", "last"\n' > $TEMPCONF
xpass cmp $TEMPCONF $OUTFILE
echo "Keep quoted trailing whitespace at end of file"
printf 'foo = "val "' > $TEMPCONF
$BOOTCONF -l $TEMPCONF > $OUTFILE
printf 'foo = "val "\n' > $TEMPCONF
xpass cmp $TEMPCONF $OUTFILE
echo "Showing correct line:column of no closing brace"
cat > $TEMPCONF << EOF
foo {