From: Eduardo Mucelli Rezende Oliveira <edumucelli@gmail.com>
To: mhiramat@kernel.org
Cc: akpm@linux-foundation.org, rostedt@goodmis.org,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/3] bootconfig: Trim unquoted values at end of file
Date: Tue, 10 Nov 2026 20:08:46 +0100 [thread overview]
Message-ID: <31f248f330e716b925add3a0ba76f62826527312.1794337724.git.edumucelli@gmail.com> (raw)
In-Reply-To: <cover.1794337724.git.edumucelli@gmail.com>
__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.
Fixes: 76db5a27a827 ("bootconfig: Add Extra Boot Config support")
Signed-off-by: Eduardo Mucelli Rezende Oliveira <edumucelli@gmail.com>
---
I tested inputs ending in unquoted spaces, tabs and carriage returns,
including arrays and appended or overridden values. The checks compare
the parser's actual values and the tool's rendered kernel command line.
Quoted whitespace and inputs ending in delimiters are controls.
The original parser fails nine of the 18 focused checks. With the fix,
all 18 pass, independently and in the combined series. The full
bootconfig test suite also passes with the regression checks added.
lib/bootconfig.c | 5 +++--
tools/bootconfig/test-bootconfig.sh | 18 ++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index 819685d6c68d..bd071c394c36 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -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 */
diff --git a/tools/bootconfig/test-bootconfig.sh b/tools/bootconfig/test-bootconfig.sh
index 530ce7e28d63..a2e8311d4d19 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 "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 {
--
2.53.0
next prev parent reply other threads:[~2026-11-10 19:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 18:05 [PATCH 0/3] bootconfig: Preserve values and key paths during parsing and output Eduardo Mucelli Rezende Oliveira
2026-11-10 18:05 ` [PATCH 1/3] tools/bootconfig: Close only opened braces in compact output Eduardo Mucelli Rezende Oliveira
2026-11-10 18:06 ` [PATCH 2/3] bootconfig: Trim unquoted values at end of file Eduardo Mucelli Rezende Oliveira
2026-11-10 18:06 ` [PATCH 3/3] tools/bootconfig: Preserve values containing both types of quotes Eduardo Mucelli Rezende Oliveira
2026-11-10 19:08 ` [PATCH v2 0/3] bootconfig: Preserve values and key paths during parsing and output Eduardo Mucelli Rezende Oliveira
2026-11-10 19:08 ` [PATCH v2 1/3] tools/bootconfig: Close only opened braces in compact output Eduardo Mucelli Rezende Oliveira
2026-11-10 19:08 ` Eduardo Mucelli Rezende Oliveira [this message]
2026-11-10 19:08 ` [PATCH v2 3/3] tools/bootconfig: Preserve values containing both types of quotes Eduardo Mucelli Rezende Oliveira
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=31f248f330e716b925add3a0ba76f62826527312.1794337724.git.edumucelli@gmail.com \
--to=edumucelli@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®