Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf trace: avoid garbage when not printing a trace event's arguments

trace__fprintf_tp_fields may not print any tracepoint arguments. E.g., if the
argument values are all zero. Previously, this would result in a totally
uninitialized buffer being passed to fprintf, which could lead to garbage on the
console. Fix the problem by passing the number of initialized bytes fprintf.

Fixes: f11b2803bb88 ("perf trace: Allow choosing how to augment the tracepoint arguments")
Signed-off-by: Benjamin Peterson <benjamin@engflow.com>
Tested-by: Howard Chu <howardchu95@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/r/20241103204816.7834-1-benjamin@engflow.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Benjamin Peterson and committed by
Namhyung Kim
5fb8e565 29bf07bc

+1 -1
+1 -1
tools/perf/builtin-trace.c
··· 3087 3087 printed += syscall_arg_fmt__scnprintf_val(arg, bf + printed, size - printed, &syscall_arg, val); 3088 3088 } 3089 3089 3090 - return printed + fprintf(trace->output, "%s", bf); 3090 + return printed + fprintf(trace->output, "%.*s", (int)printed, bf); 3091 3091 } 3092 3092 3093 3093 static int trace__event_handler(struct trace *trace, struct evsel *evsel,