Skip to content

Commit

Permalink
selftests/ftrace: Use printf for backslash included command
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mhiramat authored and shuahkh committed May 28, 2020
1 parent 558ae03 commit 8e923a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions tools/testing/selftests/ftrace/test.d/functions
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ yield() {
ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
}

# Since probe event command may include backslash, explicitly use printf "%s"
# to NOT interpret it.
ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
pos=$(echo -n "${2%^*}" | wc -c) # error position
command=$(echo "$2" | tr -d ^)
pos=$(printf "%s" "${2%^*}" | wc -c) # error position
command=$(printf "%s" "$2" | tr -d ^)
echo "Test command: $command"
echo > error_log
(! echo "$command" >> "$3" ) 2> /dev/null
(! printf "%s" "$command" >> "$3" ) 2> /dev/null
grep "$1: error:" -A 3 error_log
N=$(tail -n 1 error_log | wc -c)
# " Command: " and "^\n" => 13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ esac
if grep -q "Create/append/" README && grep -q "imm-value" README; then
echo 'p:kprobes/testevent _do_fork' > kprobe_events
check_error '^r:kprobes/testevent do_exit' # DIFF_PROBE_TYPE
echo 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events

# Explicitly use printf "%s" to not interpret \1
printf "%s" 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
check_error 'p:kprobes/testevent _do_fork ^bcd=\1' # DIFF_ARG_TYPE
check_error 'p:kprobes/testevent _do_fork ^abcd=\1:u8' # DIFF_ARG_TYPE
check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"' # DIFF_ARG_TYPE
Expand Down

0 comments on commit 8e923a2

Please sign in to comment.