Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1416523ybh; Sun, 8 Mar 2020 04:01:26 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsL65g3T3Wz7XeyCVc/P62etsPR9VVinsbB6H3am/DIb0xX8qRyvtX3Zg9EnTyZ1W+uUohq X-Received: by 2002:a9d:4007:: with SMTP id m7mr9416520ote.268.1583665286423; Sun, 08 Mar 2020 04:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583665286; cv=none; d=google.com; s=arc-20160816; b=T6m9lAxvmMJ/5kPultEWPBJcWmTuz78bMeB9q7GyJ6jMttQU8etnLr6m04mApImxhu 644Lbm0DzVRGVDvkz8qsZaZ6TOf+LzALW/Q0mYnmkGori2YtwXyxPQoIhvdWsQPgrsR5 Nlo3hN65+LV7gSbygzW2mu0X4JYQWxT+8lYrLZDn5Pp7U2/ivUHbBN0ZdcXY4hN8f3fx 5WYKGA4JS5UrgwX03u34XjLgPYxG7pmm+1IkniPg6LDl9jgIgecEFaw3lp+Yna4N8Kj9 +y3eKYU6pVVlG0D907uIO6GTNk4lTCCLXSrnJi+UrTHRNGSGMjkbpJUAh4aoltHO9ZJq kULg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:to :from; bh=yj9qVmZMV4jRtTvwJzbA5btpnlQfd+Rq2E0e1LzNzSg=; b=sIiM1Ce4vHdVe2jllxyACADcRn7JoYWU0wsLQv9Q+yLh4NnjEZYqWRVonmi/qnxrWo QtzbqaiCn9Na3VaoswqoK0FEV+XN3GnR11L4o8O1bNtad2nRVm51OESBivb9Ra4jYe7n y8kQ4UUEKhC2mHGv/6JKqtYaIW6GXPEbXOtcaT6IJa5w8DU1Jte8Cvxg1xMotxAwS9Ec hPKthKKOoH/b7W1HkDrKNR/d87D292RsdutX/tmeD/HBsSbQJceWULJw2po3cYVmguK4 AurJ7XkP2oaEH+uivg7TG1BsNZuh101zSoBGdxe7/MRcBwQCub9aP5MhdqYFJr9/X8g8 P5AA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d22si4441569oti.316.2020.03.08.04.01.15; Sun, 08 Mar 2020 04:01:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726360AbgCHK7e (ORCPT + 99 others); Sun, 8 Mar 2020 06:59:34 -0400 Received: from mail1.windriver.com ([147.11.146.13]:51181 "EHLO mail1.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbgCHK7e (ORCPT ); Sun, 8 Mar 2020 06:59:34 -0400 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail1.windriver.com (8.15.2/8.15.2) with ESMTPS id 028AxKml005931 (version=TLSv1 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 8 Mar 2020 03:59:20 -0700 (PDT) Received: from pek-lpg-core2.corp.ad.wrs.com (128.224.153.41) by ALA-HCA.corp.ad.wrs.com (147.11.189.40) with Microsoft SMTP Server id 14.3.487.0; Sun, 8 Mar 2020 03:59:19 -0700 From: To: , , , , , Subject: [PATCH] perf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus. Date: Sun, 8 Mar 2020 18:59:17 +0800 Message-ID: <1583665157-349023-1-git-send-email-zhe.he@windriver.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: He Zhe NULL pointer may be passed to perf_cpu_map__cpu and then cause crash, such as the one commit cb71f7d43ece ("libperf: Setup initial evlist::all_cpus value") fix. Signed-off-by: He Zhe --- tools/perf/lib/cpumap.c | 2 +- tools/perf/lib/evlist.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c index f93f4e7..ca02150 100644 --- a/tools/perf/lib/cpumap.c +++ b/tools/perf/lib/cpumap.c @@ -247,7 +247,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) 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/perf/lib/evlist.c b/tools/perf/lib/evlist.c index 5b9f2ca..f87a239 100644 --- a/tools/perf/lib/evlist.c +++ b/tools/perf/lib/evlist.c @@ -127,6 +127,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); } -- 2.7.4