From: Julian Braha <julianbraha@gmail.com>
To: Daniel Syauqi <syauqicode@gmail.com>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nsc@kernel.org>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] scripts/config: preserve ampersands in string values
Date: Tue, 1 Dec 2026 18:06:38 +0000 [thread overview]
Message-ID: <3ccda48d-02a6-4594-92f6-b7d988cef2e4@gmail.com> (raw)
In-Reply-To: <a8f4130ea986dcd8e627962632e83e20032e50d8.1796024119.git.syauqicode@gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 2716 bytes --]
Hi Daniel,
Thanks for raising this.
On 11/30/26 07:52, Daniel Syauqi wrote:
> Setting CMDLINE to 'a=1&b=2' with --set-str works when the symbol is
(This 'a=1&b=2' example looks more like the end of a URL to me than a
boot argument...)
> absent. When replacing an existing assignment, sed expands the
> ampersand to the entire matched line. The command succeeds but writes
> a different kernel command line. Embedded quotes from the old value
> can also truncate the string on the next olddefconfig.
Improvements to input validation are good.
But, there aren't any cases of ampersands or embedded quotes in the
string constants in-tree, and I can't imagine any real-world cases where
users might encounter this.
>
> Escape backslashes and quotes when forming the Kconfig string and
> escape backslashes and ampersands when forming the sed replacement.
> This lets insertion and replacement write the same value, including
> when a backslash precedes an ampersand. Decode the escaped backslashes
> when reading the value back with --state.
>
> Fixes: 1f990cf94559 ("kbuild: add generic --set-str option to scripts/config")
> Signed-off-by: Daniel Syauqi <syauqicode@gmail.com>
> ---
> scripts/config | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/config b/scripts/config
> index 32428ea90..ba66b681d 100755
> --- a/scripts/config
> +++ b/scripts/config
> @@ -86,9 +86,10 @@ txt_append() {
>
> txt_subst() {
> local before="$1"
> - local after="$2"
> + local after="${2//\\/\\\\}"
> local infile="$3"
>
> + after="${after//&/\\&}"
> sed -E -i.swp -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile"
> SED_EDITED=1
> }
> @@ -186,8 +187,9 @@ while [ "$1" != "" ] ; do
> ;;
>
> --set-str)
> - # sed swallows one level of escaping, so we need double-escaping
> - set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\""
> + # Escape backslashes and double quotes in the Kconfig string.
> + value="${1//\\/\\\\}"
> + set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${value//\"/\\\"}\""
> shift
> ;;
Sashiko alarmed on this hunk regarding usage with bash 5.2, but it seems
to be a classic AI hallucination.
>
> @@ -211,6 +213,7 @@ while [ "$1" != "" ] ; do
> V="${V/#\"/}"
> V="${V/%\"/}"
> V="${V//\\\"/\"}"
> + V="${V//\\\\/\\}"
> echo "${V}"
> fi
> fi
>
These substitution changes further complicate some already tricky code
(and lack a real-world example). But, the changes look technically
correct to me, so:
Tested-by: Julian Braha <julianbraha@gmail.com>
Reviewed-by: Julian Braha <julianbraha@gmail.com>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
next prev parent reply other threads:[~2026-12-01 18:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 7:52 [PATCH 0/2] scripts/config: fix string handling in --set-str and --state Daniel Syauqi
2026-11-30 7:52 ` [PATCH 1/2] scripts/config: preserve ampersands in string values Daniel Syauqi
2026-12-01 7:53 ` sashiko-bot
2026-12-01 18:05 ` Julian Braha
2026-12-01 18:06 ` Julian Braha [this message]
2026-12-02 2:01 ` Daniel Syauqi
2026-11-30 7:52 ` [PATCH 2/2] scripts/config: print string values literally with --state Daniel Syauqi
2026-12-01 18:06 ` Julian Braha
2026-12-01 18:12 ` Randy Dunlap
2026-12-01 18:26 ` Julian Braha
2026-12-02 2:01 ` Daniel Syauqi
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=3ccda48d-02a6-4594-92f6-b7d988cef2e4@gmail.com \
--to=julianbraha@gmail.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=syauqicode@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.