From: Benjamin Peterson <benjamin@engflow.com>
To: acme@kernel.org
Cc: adrian.hunter@intel.com, alexander.shishkin@linux.intel.com,
benjamin@engflow.com, howardchu95@gmail.com, irogers@google.com,
jolsa@kernel.org, kan.liang@linux.intel.com,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
mark.rutland@arm.com, mingo@redhat.com, namhyung@kernel.org,
peterz@infradead.org
Subject: [PATCH v3] perf trace: avoid garbage when not printing a trace event's arguments
Date: Sun, 3 Nov 2024 20:48:16 +0000 [thread overview]
Message-ID: <20241103204816.7834-1-benjamin@engflow.com> (raw)
In-Reply-To: <ZyV0a6e_46R9pmQw@x1>
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>
---
tools/perf/builtin-trace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index d3f11b90d025..5af55f4192b5 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -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);
+ return printed + fprintf(trace->output, "%.*s", (int)printed, bf);
}
static int trace__event_handler(struct trace *trace, struct evsel *evsel,
--
2.39.5
next prev parent reply other threads:[~2024-11-03 20:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-01 0:53 [PATCH] perf trace: avoid garbage when not printing an trace event's arguments Benjamin Peterson
2024-11-01 2:03 ` Howard Chu
2024-11-01 17:26 ` Benjamin Peterson
2024-11-01 17:27 ` [PATCH v2] perf trace: avoid garbage when not printing a " Benjamin Peterson
2024-11-01 21:00 ` Howard Chu
2024-11-01 21:30 ` Arnaldo Carvalho de Melo
2024-11-01 21:41 ` Benjamin Peterson
2024-11-02 0:38 ` Arnaldo Carvalho de Melo
2024-11-03 20:48 ` Benjamin Peterson [this message]
2024-11-05 18:52 ` [PATCH v3] " Arnaldo Carvalho de Melo
2024-11-06 17:03 ` Namhyung Kim
2024-11-03 4:54 ` [PATCH] perf trace: avoid garbage when not printing an " kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241103204816.7834-1-benjamin@engflow.com \
--to=benjamin@engflow.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=howardchu95@gmail.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).