The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/2] scripts/config: fix string handling in --set-str and --state
@ 2026-11-30  7:52 Daniel Syauqi
  2026-11-30  7:52 ` [PATCH 1/2] scripts/config: preserve ampersands in string values Daniel Syauqi
  2026-11-30  7:52 ` [PATCH 2/2] scripts/config: print string values literally with --state Daniel Syauqi
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel Syauqi @ 2026-11-30  7:52 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier; +Cc: linux-kbuild, linux-kernel

Two operations in scripts/config can silently change a string. When
--set-str updates an existing assignment, an ampersand in the new value
expands to the old config line. When --state reads a string such as
"-n", echo consumes it as an option and the query writes no output.

The first patch fixes the escaping on the update path. The second fixes
readback and can be reproduced with a hand-written .config.

Both failures were reproduced on v7.4-rc5 in an arm64 Lima guest. With
the series applied, an out-of-tree arm64 defconfig retained the literal
CMDLINE value "a=1&b=2" and LOCALVERSION "-n" across make olddefconfig.
Chained --state queries returned both values, each on its own line.

I used OpenAI Codex to identify both bugs, draft the fixes and commit
messages, and run the tests in Lima.

Daniel Syauqi (2):
  scripts/config: preserve ampersands in string values
  scripts/config: print string values literally with --state

 scripts/config | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)


base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] scripts/config: preserve ampersands in string values
  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 ` Daniel Syauqi
  2026-11-30  7:52 ` [PATCH 2/2] scripts/config: print string values literally with --state Daniel Syauqi
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Syauqi @ 2026-11-30  7:52 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier; +Cc: linux-kbuild, linux-kernel

Setting CMDLINE to 'a=1&b=2' with --set-str works when the symbol is
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.

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
 		;;
 
@@ -211,6 +213,7 @@ while [ "$1" != "" ] ; do
 				V="${V/#\"/}"
 				V="${V/%\"/}"
 				V="${V//\\\"/\"}"
+				V="${V//\\\\/\\}"
 				echo "${V}"
 			fi
 		fi

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] scripts/config: print string values literally with --state
  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-11-30  7:52 ` Daniel Syauqi
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Syauqi @ 2026-11-30  7:52 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier; +Cc: linux-kbuild, linux-kernel

With CONFIG_LOCALVERSION="-n", querying --state LOCALVERSION exits
successfully without printing any bytes. Bash's echo interprets the
decoded string as an option. Values such as "-e" yield only a newline.

Use printf with a fixed format so that each query produces the value
followed by a newline, including when multiple queries are chained.

Fixes: d6686da814c8 ("scripts/config: properly report and set string options")
Signed-off-by: Daniel Syauqi <syauqicode@gmail.com>
---
 scripts/config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/config b/scripts/config
index ba66b681d..143dae061 100755
--- a/scripts/config
+++ b/scripts/config
@@ -214,7 +214,7 @@ while [ "$1" != "" ] ; do
 				V="${V/%\"/}"
 				V="${V//\\\"/\"}"
 				V="${V//\\\\/\\}"
-				echo "${V}"
+				printf '%s\n' "$V"
 			fi
 		fi
 		;;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-30  7:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-11-30  7:52 ` [PATCH 2/2] scripts/config: print string values literally with --state Daniel Syauqi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox