summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-09-08 15:07:20 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-09-09 08:10:17 -0300
commit93fd7adf1a47c61ef81b33c8fdd9cb4e4ea0bdcb (patch)
treec72f3ac17c82c54c4e62aeeb808b5c54b52c801e
parentaa18964dd64511305de0711fed912054da6f5d18 (diff)
downloadlinux-next-93fd7adf1a47c61ef81b33c8fdd9cb4e4ea0bdcb.tar.gz
linux-next-93fd7adf1a47c61ef81b33c8fdd9cb4e4ea0bdcb.zip
perf stat: Avoid uninitialized memory read on error
If has_supported_counters fails then msg was passed to ui__error regardless of whether an error was written into msg leading to reading uninitialized memory. Avoid this by always terminating msg at initialization. Opportunistically reduce the scope of msg to make its use clearer. Fixes: c9a8c343ef2f ("perf stat: When no events, don't report an error if there is none") Signed-off-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20260908220720.564614-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-stat.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c50cf230f16e..37752d6bfef4 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -777,7 +777,6 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
int interval = stat_config.interval;
int times = stat_config.times;
int timeout = stat_config.timeout;
- char msg[BUFSIZ];
unsigned long long t0, t1;
struct evsel *counter;
size_t l;
@@ -908,6 +907,9 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
}
}
if (!has_supported_counters && !stat_config.null_run) {
+ char msg[BUFSIZ];
+
+ msg[0] = '\0';
if (open_err) {
evsel__open_strerror(evlist__first(evsel_list), &target, open_err,
msg, sizeof(msg));