Skip to content

Commit 1302e35

Browse files
benjaminpacmel
authored andcommitted
perf trace: Avoid garbage when not printing a syscall's arguments
syscall__scnprintf_args may not place anything in the output buffer (e.g., because the arguments are all zero). If that happened in trace__fprintf_sys_enter, its fprintf would receive an unitialized buffer leading to garbage output. Fix the problem by passing the (possibly zero) bounds of the argument buffer to the output fprintf. Fixes: a98392b ("perf trace: Use beautifiers on syscalls:sys_enter_ handlers") Signed-off-by: Benjamin Peterson <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Tested-by: Howard Chu <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 3fd7c36 commit 1302e35

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tools/perf/builtin-trace.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,6 +2702,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,
27022702
char msg[1024];
27032703
void *args, *augmented_args = NULL;
27042704
int augmented_args_size;
2705+
size_t printed = 0;
27052706

27062707
if (sc == NULL)
27072708
return -1;
@@ -2717,8 +2718,8 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,
27172718

27182719
args = perf_evsel__sc_tp_ptr(evsel, args, sample);
27192720
augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_syscalls_args_size);
2720-
syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread);
2721-
fprintf(trace->output, "%s", msg);
2721+
printed += syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread);
2722+
fprintf(trace->output, "%.*s", (int)printed, msg);
27222723
err = 0;
27232724
out_put:
27242725
thread__put(thread);

0 commit comments

Comments
 (0)