Re: [PATCH] perf trace: avoid garbage when not printing an trace event's arguments
From: Howard Chu
Date: Thu Oct 31 2024 - 22:03:30 EST
Hello Benjamin,
It does not build on my system due to this warning:
builtin-trace.c: In function ‘trace__fprintf_tp_fields’:
builtin-trace.c:3090:35: error: field precision specifier ‘.*’ expects
argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long
unsigned int’} [-Werror=format=]
3090 | fprintf(trace->output, "%.*s", printed, bf);
| ~~^~ ~~~~~~~
| | |
| int size_t {aka long unsigned int}
Thanks,
Howard
On Thu, Oct 31, 2024 at 5:54 PM Benjamin Peterson <benjamin@xxxxxxxxxxx> wrote:
>
> 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.
>
> Remove the return value of trace__fprintf_tp_fields, since it was meaningless
> and ignored.
>
> Fixes: f11b2803bb88 ("perf trace: Allow choosing how to augment the tracepoint arguments")
> Signed-off-by: Benjamin Peterson <benjamin@xxxxxxxxxxx>
> ---
> tools/perf/builtin-trace.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index d3f11b90d025..e93f795e680f 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -3021,7 +3021,7 @@ static void bpf_output__fprintf(struct trace *trace,
> ++trace->nr_events_printed;
> }
>
> -static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample *sample,
> +static void trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample *sample,
> struct thread *thread, void *augmented_args, int augmented_args_size)
> {
> char bf[2048];
> @@ -3087,7 +3087,7 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel,
> printed += syscall_arg_fmt__scnprintf_val(arg, bf + printed, size - printed, &syscall_arg, val);
> }
>
> - return printed + fprintf(trace->output, "%s", bf);
> + fprintf(trace->output, "%.*s", printed, bf);
> }
>
> static int trace__event_handler(struct trace *trace, struct evsel *evsel,
> --
> 2.39.5
>
>