Commit ceb75476 authored by Leo Yan's avatar Leo Yan Committed by Arnaldo Carvalho de Melo

perf hists browser: Fix potential NULL pointer dereference found by the smatch tool

Based on the following report from Smatch, fix the potential
NULL pointer dereference check.

  tools/perf/ui/browsers/hists.c:641
  hist_browser__run() error: we previously assumed 'hbt' could be
  null (see line 625)

  tools/perf/ui/browsers/hists.c:3088
  perf_evsel__hists_browse() error: we previously assumed
  'browser->he_selection' could be null (see line 2902)

  tools/perf/ui/browsers/hists.c:3272
  perf_evsel_menu__run() error: we previously assumed 'hbt' could be
  null (see line 3260)

This patch firstly validating the pointers before access them, so can
fix potential NULL pointer dereference.
Signed-off-by: default avatarLeo Yan <leo.yan@linaro.org>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lkml.kernel.org/r/20190708143937.7722-2-leo.yan@linaro.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 0702f23c
...@@ -639,6 +639,10 @@ int hist_browser__run(struct hist_browser *browser, const char *help, ...@@ -639,6 +639,10 @@ int hist_browser__run(struct hist_browser *browser, const char *help,
switch (key) { switch (key) {
case K_TIMER: { case K_TIMER: {
u64 nr_entries; u64 nr_entries;
WARN_ON_ONCE(!hbt);
if (hbt)
hbt->timer(hbt->arg); hbt->timer(hbt->arg);
if (hist_browser__has_filter(browser) || if (hist_browser__has_filter(browser) ||
...@@ -2821,7 +2825,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, ...@@ -2821,7 +2825,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
{ {
struct hists *hists = evsel__hists(evsel); struct hists *hists = evsel__hists(evsel);
struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env, annotation_opts); struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env, annotation_opts);
struct branch_info *bi; struct branch_info *bi = NULL;
#define MAX_OPTIONS 16 #define MAX_OPTIONS 16
char *options[MAX_OPTIONS]; char *options[MAX_OPTIONS];
struct popup_action actions[MAX_OPTIONS]; struct popup_action actions[MAX_OPTIONS];
...@@ -3087,6 +3091,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, ...@@ -3087,6 +3091,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
goto skip_annotation; goto skip_annotation;
if (sort__mode == SORT_MODE__BRANCH) { if (sort__mode == SORT_MODE__BRANCH) {
if (browser->he_selection)
bi = browser->he_selection->branch_info; bi = browser->he_selection->branch_info;
if (bi == NULL) if (bi == NULL)
...@@ -3271,6 +3277,7 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu, ...@@ -3271,6 +3277,7 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu,
switch (key) { switch (key) {
case K_TIMER: case K_TIMER:
if (hbt)
hbt->timer(hbt->arg); hbt->timer(hbt->arg);
if (!menu->lost_events_warned && if (!menu->lost_events_warned &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment