Skip to content

Commit eead8a0

Browse files
captain5050acmel
authored andcommitted
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 <[email protected]> Acked-by: Gautam Menghani <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 21fb366 commit eead8a0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/lib/perf/threadmap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,10 @@ int perf_thread_map__nr(struct perf_thread_map *threads)
9797

9898
pid_t perf_thread_map__pid(struct perf_thread_map *map, int idx)
9999
{
100+
if (!map) {
101+
assert(idx == 0);
102+
return -1;
103+
}
104+
100105
return map->map[idx].pid;
101106
}

0 commit comments

Comments
 (0)