From: He Zhe Date: Sun, 8 Mar 2020 10:59:17 +0000 (+0800) Subject: libperf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus. X-Git-Tag: v5.15~3782^2~10^2~59 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=44d041b7b2c11b6739501fd3763cc6fed62cf0ed;p=platform%2Fkernel%2Flinux-starfive.git libperf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus. A NULL pointer may be passed to perf_cpu_map__cpu and then cause a crash, such as the one commit cb71f7d43ece ("libperf: Setup initial evlist::all_cpus value") fix. Signed-off-by: He Zhe Acked-by: Jiri Olsa Cc: Andi Kleen Cc: Kyle Meyer Link: http://lore.kernel.org/lkml/1583665157-349023-1-git-send-email-zhe.he@windriver.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index f93f4e7..ca02150 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -247,7 +247,7 @@ out: int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx) { - if (idx < cpus->nr) + if (cpus && idx < cpus->nr) return cpus->map[idx]; return -1; diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index def5505..c481b62 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -125,6 +125,7 @@ void perf_evlist__exit(struct perf_evlist *evlist) perf_cpu_map__put(evlist->cpus); perf_thread_map__put(evlist->threads); evlist->cpus = NULL; + evlist->all_cpus = NULL; evlist->threads = NULL; fdarray__exit(&evlist->pollfd); }