summaryrefslogtreecommitdiff
path: root/tools/lib/perf
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2025-05-19 12:51:38 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2025-05-21 15:07:13 -0300
commiteead8a0114775c7250ae27197ac3f3e5bbc567df (patch)
tree46c22de59209d1d173be95b69953496a960f2842 /tools/lib/perf
parent21fb366b2f45761125230e89a73c0fe29d55d9cf (diff)
libperf threadmap: Don't segv for index 0 for the NULL 'struct perf_thread_map' pointer
perf_thread_map__nr() returns length 1 if the perf_thread_map is NULL, meaning index 0 is valid. When perf_thread_map__pid() of index 0 is read then return the expected "any" -1 value. Assert this is only done for index 0. Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Gautam Menghani <gautam@linux.ibm.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Howard Chu <howardchu95@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20250519195148.1708988-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/perf')
-rw-r--r--tools/lib/perf/threadmap.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/tools/lib/perf/threadmap.c b/tools/lib/perf/threadmap.c
index 07968f3ea093..3ca9ba4987fc 100644
--- a/tools/lib/perf/threadmap.c
+++ b/tools/lib/perf/threadmap.c
@@ -97,5 +97,10 @@ int perf_thread_map__nr(struct perf_thread_map *threads)
pid_t perf_thread_map__pid(struct perf_thread_map *map, int idx)
{
+ if (!map) {
+ assert(idx == 0);
+ return -1;
+ }
+
return map->map[idx].pid;
}