[PATCH 5/5] tools/bootconfig: Match literal keys in tracing script helpers

From: Eduardo Mucelli Rezende Oliveira

Date: Sat Oct 31 2026 - 14:36:09 EST


The xbc shell helpers interpolate bootconfig keys into regular expressions.
Dots in keys consequently match arbitrary characters: asking for
ftrace.options can also return ftraceXoptions. Branch and subkey lookups
also match unrelated keys that merely share the requested prefix.

Compare complete keys literally and require a dot at descendant boundaries.
Keep the optional subkey pattern operating on the suffix only.

Fixes: 7e66ef0046cc ("tools/bootconfig: Add a script to generate ftrace shell-command from bootconfig")
Signed-off-by: Eduardo Mucelli Rezende Oliveira <edumucelli@xxxxxxxxx>
---
The helper checks cover literal dotted keys, missing keys, branch
boundaries and subkey selection. The original helpers passed one of
five checks; the fixed helpers pass all five. These checks also pass
when combined with the other fixes in this series.

tools/bootconfig/scripts/xbc.sh | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/bootconfig/scripts/xbc.sh b/tools/bootconfig/scripts/xbc.sh
index 1f0ebf50dd2d..16ee590661b4 100644
--- a/tools/bootconfig/scripts/xbc.sh
+++ b/tools/bootconfig/scripts/xbc.sh
@@ -36,21 +36,26 @@ xbc_get_val() { # key [maxnum]
if [ "$2" ]; then
MAXOPT="-L $2"
fi
- grep "^$1 =" $XBC_TMPFILE | cut -d= -f2- | \
+ awk -v key="$1" '$1 == key && $2 == "="' "$XBC_TMPFILE" | cut -d= -f2- | \
sed -e 's/", /" /g' -e "s/',/' /g" | \
xargs $MAXOPT -n 1 echo
}

xbc_has_key() { # key
- grep -q "^$1 =" $XBC_TMPFILE
+ awk -v key="$1" '$1 == key && $2 == "=" { found = 1 }
+ END { exit !found }' "$XBC_TMPFILE"
}

xbc_has_branch() { # prefix-key
- grep -q "^$1" $XBC_TMPFILE
+ awk -v key="$1" '$1 == key || index($1, key ".") == 1 { found = 1 }
+ END { exit !found }' "$XBC_TMPFILE"
}

xbc_subkeys() { # prefix-key depth [subkey-pattern]
__keys=`echo $1 | sed "s/\./ /g"`
__s=`nr_args $__keys`
- grep "^$1$3" $XBC_TMPFILE | cut -d= -f1| cut -d. -f$((__s + 1))-$((__s + $2)) | uniq
+ awk -v key="$1" -v pattern="$3" '
+ index($1, key ".") == 1 &&
+ substr($1, length(key) + 1) ~ ("^" pattern) { print $1 }
+ ' "$XBC_TMPFILE" | cut -d. -f$((__s + 1))-$((__s + $2)) | uniq
}
--
2.53.0