All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Syauqi" <syauqicode@gmail.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>
Cc: linux-kbuild@vger.kernel.org
Subject: Re: [PATCH 1/2] scripts/config: preserve ampersands in string values
Date: Tue, 01 Dec 2026 07:53:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-242798@kernel.org> (raw)
In-Reply-To: <a8f4130ea986dcd8e627962632e83e20032e50d8.1796024119.git.syauqicode@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scripts/config: broken backslash and ampersand escaping on Bash
  5.2+
--

commit b78b433a507d0a53d91d8991945248e47628caf3
Author: Daniel Syauqi <syauqicode@gmail.com>

scripts/config: preserve ampersands in string values

This commit escapes backslashes, double quotes, and ampersands when setting
Kconfig string values and running sed replacements in scripts/config, and
unescapes backslashes when reading string values with --state.

> diff --git a/scripts/config b/scripts/config
> index 32428ea909c2c..ba66b681d7429 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
>  		;;

[Severity: Low]
Does the double-quoted ${...//.../...} replacement in txt_subst() and
--set-str lose one level of backslash escaping on bash 5.2 and newer?

Bash 5.2 enables the patsub_replacement shell option by default, where &
in the replacement string expands to the match and \ escapes & and \.
Outer double quotes around ${parameter//pattern/replacement} do not disable
patsub_replacement; instead, the outer double quotes halve the backslashes
first and patsub_replacement consumes the remaining escape.  As a result,
"${after//&/\\&}" leaves & unescaped for sed, and "${2//\\/\\\\}" and
"${1//\\/\\\\}" collapse four backslashes to a single literal backslash,
causing sed to expand & to the matched line or strip backslashes from
escaped double quotes when updating an existing symbol.

Quoting the replacement string itself (for example, ${after//&/"\\&"} and
${1//\\/"\\\\"}) or removing the outer double quotes prevents double-quote
backslash reduction before patsub_replacement runs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796024119.git.syauqicode@gmail.com?part=1

  reply	other threads:[~2026-12-01  7:53 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 [this message]
2026-12-01 18:05   ` Julian Braha
2026-12-01 18:06   ` Julian Braha
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=sashiko-outbox-242798@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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.