Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp342389ybg; Fri, 12 Jun 2020 03:03:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpjfgCiSDKSidVdsL/SjW+x2fmbQqEms6zt3ghCJHrfd3g+9T10U0ZyRoarEMC01MZx5/4 X-Received: by 2002:a05:6402:1285:: with SMTP id w5mr11099172edv.73.1591956214180; Fri, 12 Jun 2020 03:03:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591956214; cv=none; d=google.com; s=arc-20160816; b=tV8w+NSfQbHWteBLsCBW4yqYtBz+OzgX3PKSZ/v3E+Oozwy0Nhw1DXk31UZizDnxAk EvSyjnTzyNoU64en2ZMOgYsK/AJnjaWi2yR359yXLJhdReEHCC3EC5Q7vALJDZ3IT4BN usmnwcBa2mxFb8IqdPme+WO+PEYqKKKseLKvx4apk3FybrdBM04qPl4bmhDkuwaKBJYp pRNWX4F+1tetTW/ZoMKbymn5MYZn95fJGOi0a4bx4QDH64f4HdCGF83CRsH/GWZ24Yf8 AZmDEgJ7MbO6iT+DJhmLGE4+MzSRL7BNdCES1Hd4elWv1zHPfGE9rUDoxt9yR4DYp5XQ 9Zvg== 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:cc :to:from; bh=ld0veW+9/Yg/340givtxYjahjx7J+q3jUGNfjfd4TAg=; b=hreObn4bdx9/UWTO4k8m69kbYc5S2BXMAC2+iW2IttqskTSldcoO3GY2HrVec4hdF+ mVG2IGO1NhkH2oORMaEUoIJDWoy1zHP2cbzqmqKdPSe1zizHcSN6qrVdcOYswCRGiVsC RYg9ZILeGd8zz2aV97nCvlG3disYGJ4zWxl8jivnqaQN5cZIxF3ev5O5m9LACQLor1x7 jklDnagbIN2XwX/s0tPrXVl5WP16YVlLZhjlp+ErOdZkKekpc6JuqEx+XzqMcbLo2LbQ GHsQXlTjRTAnMd+BhNcjE7hPcVK9cgl77tcGGdudDfVx/ZhHoX/7wRb+sb+RTI6vKULK wSGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 23si3655225ejy.621.2020.06.12.03.03.10; Fri, 12 Jun 2020 03:03:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726277AbgFLJ7B (ORCPT + 99 others); Fri, 12 Jun 2020 05:59:01 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60204 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725805AbgFLJ7A (ORCPT ); Fri, 12 Jun 2020 05:59:00 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 112A5712528E0DF3EFC4; Fri, 12 Jun 2020 17:58:55 +0800 (CST) Received: from euler.huawei.com (10.175.124.27) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Fri, 12 Jun 2020 17:58:47 +0800 From: Wei Li To: Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , "Namhyung Kim" CC: , Jin Yao , "Andi Kleen" , Subject: [PATCH] perf report TUI: Fix segmentation fault in perf_evsel__hists_browse() Date: Fri, 12 Jun 2020 17:43:22 +0800 Message-ID: <20200612094322.39565-1-liwei391@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The segmentation fault can be reproduced as following steps: 1) Executing perf report in tui. 2) Typing '/xxxxx' to filter the symbol to get nothing matched. 3) Pressing enter with no entry selected. Then it will report a segmentation fault. It is caused by the lack of check of browser->he_selection when accessing it's member res_samples in perf_evsel__hists_browse(). These processes are meaningful for specified samples, so we can skip these when nothing is selected. Fixes: 4968ac8fb7c3 ("perf report: Implement browsing of individual samples") Signed-off-by: Wei Li --- tools/perf/ui/browsers/hists.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 487e54ef56a9..2101b6b770d8 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -2288,6 +2288,11 @@ static struct thread *hist_browser__selected_thread(struct hist_browser *browser return browser->he_selection->thread; } +static struct res_sample *hist_browser__selected_res_sample(struct hist_browser *browser) +{ + return browser->he_selection ? browser->he_selection->res_samples : NULL; +} + /* Check whether the browser is for 'top' or 'report' */ static inline bool is_report_browser(void *timer) { @@ -3357,16 +3362,16 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events, &options[nr_options], NULL, NULL, evsel); nr_options += add_res_sample_opt(browser, &actions[nr_options], &options[nr_options], - hist_browser__selected_entry(browser)->res_samples, - evsel, A_NORMAL); + hist_browser__selected_res_sample(browser), + evsel, A_NORMAL); nr_options += add_res_sample_opt(browser, &actions[nr_options], &options[nr_options], - hist_browser__selected_entry(browser)->res_samples, - evsel, A_ASM); + hist_browser__selected_res_sample(browser), + evsel, A_ASM); nr_options += add_res_sample_opt(browser, &actions[nr_options], &options[nr_options], - hist_browser__selected_entry(browser)->res_samples, - evsel, A_SOURCE); + hist_browser__selected_res_sample(browser), + evsel, A_SOURCE); nr_options += add_switch_opt(browser, &actions[nr_options], &options[nr_options]); skip_scripting: -- 2.17.1