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 3/3] tools/bootconfig: Preserve values containing both types of quotes
Date: Tue, 10 Nov 2026 20:08:47 +0100 [thread overview]
Message-ID: <6ad95c1a6eb524143a38ef9a0d4fd87b92ef1daa.1794337724.git.edumucelli@gmail.com> (raw)
In-Reply-To: <cover.1794337724.git.edumucelli@gmail.com>
An unquoted bootconfig value can contain both single and double quote
characters, for example:
message = He said "it's fine"
xbc_show_value() surrounds any value containing a double quote with
single quotes. If the value also contains a single quote, both compact
and list output become invalid bootconfig syntax and cannot be parsed
again.
Print values containing both quote types without outer quotes. Such
values can only come from unquoted input, so they do not contain the
delimiters that would require quoting. Keep using single or double
quotes for the other values. Add round-trip checks for compact and list
output, including an array containing the mixed-quote value.
Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
Signed-off-by: Eduardo Mucelli Rezende Oliveira <edumucelli@gmail.com>
---
The parser accepts message = He said "it's fine", but the original tool
prints a value surrounded by single quotes. The apostrophe in "it's"
then makes that output invalid.
I checked scalar and array values through compact and list output,
including literal backslashes, quote controls, and a test initrd image.
With the fix, all 25 focused checks pass, independently and in the
combined series, and the parsed values survive those round trips.
The full bootconfig test suite also passes.
tools/bootconfig/main.c | 14 ++++++++------
tools/bootconfig/test-bootconfig.sh | 11 +++++++++++
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 75516e9e4ac3..e7513742fd2f 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -52,17 +52,19 @@ static int init_xbc_with_error(char *buf, int len)
static int xbc_show_value(struct xbc_node *node, bool semicolon)
{
- const char *val, *eol;
- char q;
+ const char *val, *eol, *q;
int i = 0;
eol = semicolon ? ";\n" : "\n";
xbc_array_for_each_value(node, val) {
- if (strchr(val, '"'))
- q = '\'';
+ if (!strchr(val, '"'))
+ q = "\"";
+ else if (!strchr(val, '\''))
+ q = "'";
else
- q = '"';
- printf("%c%s%c%s", q, val, q, xbc_node_is_array(node) ? ", " : eol);
+ /* Both types of quotes can only occur in unquoted values. */
+ q = "";
+ printf("%s%s%s%s", q, val, q, xbc_node_is_array(node) ? ", " : eol);
i++;
}
return i;
diff --git a/tools/bootconfig/test-bootconfig.sh b/tools/bootconfig/test-bootconfig.sh
index a2e8311d4d19..a0578013e731 100755
--- a/tools/bootconfig/test-bootconfig.sh
+++ b/tools/bootconfig/test-bootconfig.sh
@@ -146,6 +146,17 @@ $BOOTCONF $INITRD > $TEMPCONF
cat $TEMPCONF
xpass grep \'\"string\"\' $TEMPCONF
+echo "Round-trip values containing both types of quotes"
+cat > $TEMPCONF << 'EOF'
+key = "first", He said "it's fine", "last"
+EOF
+for mode in "" "-l"; do
+ $BOOTCONF $mode $TEMPCONF > $OUTFILE
+ xpass $BOOTCONF -a $OUTFILE $INITRD
+ $BOOTCONF -l $INITRD > $OUTFILE
+ xpass cmp $TEMPCONF $OUTFILE
+done
+
echo "Repeat same-key tree"
cat > $TEMPCONF << EOF
foo
--
2.53.0
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 ` [PATCH v2 2/3] bootconfig: Trim unquoted values at end of file Eduardo Mucelli Rezende Oliveira
2026-11-10 19:08 ` Eduardo Mucelli Rezende Oliveira [this message]
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=6ad95c1a6eb524143a38ef9a0d4fd87b92ef1daa.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®