Skip to content

Commit 8e923a2

Browse files
mhiramatshuahkh
authored andcommitted
selftests/ftrace: Use printf for backslash included command
Since the built-in echo has different behavior in POSIX shell (dash) and bash, kprobe_syntax_errors.tc can fail on dash which interpret backslash escape automatically. To fix this issue, we explicitly use printf "%s" (not interpret backslash escapes) if the command string can include backslash. Reported-by: Liu Yiding <[email protected]> Suggested-by: Xiao Yang <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 558ae03 commit 8e923a2

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

tools/testing/selftests/ftrace/test.d/functions

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,14 @@ yield() {
119119
ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
120120
}
121121

122+
# Since probe event command may include backslash, explicitly use printf "%s"
123+
# to NOT interpret it.
122124
ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
123-
pos=$(echo -n "${2%^*}" | wc -c) # error position
124-
command=$(echo "$2" | tr -d ^)
125+
pos=$(printf "%s" "${2%^*}" | wc -c) # error position
126+
command=$(printf "%s" "$2" | tr -d ^)
125127
echo "Test command: $command"
126128
echo > error_log
127-
(! echo "$command" >> "$3" ) 2> /dev/null
129+
(! printf "%s" "$command" >> "$3" ) 2> /dev/null
128130
grep "$1: error:" -A 3 error_log
129131
N=$(tail -n 1 error_log | wc -c)
130132
# " Command: " and "^\n" => 13

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ esac
9191
if grep -q "Create/append/" README && grep -q "imm-value" README; then
9292
echo 'p:kprobes/testevent _do_fork' > kprobe_events
9393
check_error '^r:kprobes/testevent do_exit' # DIFF_PROBE_TYPE
94-
echo 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
94+
95+
# Explicitly use printf "%s" to not interpret \1
96+
printf "%s" 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
9597
check_error 'p:kprobes/testevent _do_fork ^bcd=\1' # DIFF_ARG_TYPE
9698
check_error 'p:kprobes/testevent _do_fork ^abcd=\1:u8' # DIFF_ARG_TYPE
9799
check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"' # DIFF_ARG_TYPE

0 commit comments

Comments
 (0)