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 > --- > 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 Reviewed-by: Julian Braha