[PATCH v1 01/11] perf report: Smatch: Fix potential NULL pointer dereference

From: Leo Yan
Date: Tue Jul 02 2019 - 06:36:01 EST


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

tools/perf/builtin-report.c:304
process_read_event() error: we previously assumed 'evsel' could be null (see line 301)

tools/perf/builtin-report.c
301 const char *name = evsel ? perf_evsel__name(evsel) : "unknown";
302 int err = perf_read_values_add_value(&rep->show_threads_values,
303 event->read.pid, event->read.tid,
304 evsel->idx,
^^^^^^^
305 name,
306 event->read.value);

This patch checks if 'evsel' is NULL pointer then pass UINT64_MAX as idx
parameter.

Signed-off-by: Leo Yan <leo.yan@xxxxxxxxxx>
---
tools/perf/builtin-report.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 91c40808380d..a894ce7cd04e 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -299,10 +299,10 @@ static int process_read_event(struct perf_tool *tool,

if (rep->show_threads) {
const char *name = evsel ? perf_evsel__name(evsel) : "unknown";
+ int idx = evsel ? evsel->idx : INT_MAX;
int err = perf_read_values_add_value(&rep->show_threads_values,
event->read.pid, event->read.tid,
- evsel->idx,
- name,
+ idx, name,
event->read.value);

if (err)
--
2.17.1