[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190702103420.27540-6-leo.yan@linaro.org>
Date: Tue, 2 Jul 2019 18:34:14 +0800
From: Leo Yan <leo.yan@...aro.org>
To: Arnaldo Carvalho de Melo <acme@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...hat.com>,
Namhyung Kim <namhyung@...nel.org>,
Mathieu Poirier <mathieu.poirier@...aro.org>,
Suzuki K Poulose <suzuki.poulose@....com>,
Andi Kleen <ak@...ux.intel.com>,
"David S. Miller" <davem@...emloft.net>,
Davidlohr Bueso <dave@...olabs.net>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Jin Yao <yao.jin@...ux.intel.com>,
Song Liu <songliubraving@...com>,
Adrian Hunter <adrian.hunter@...el.com>,
Alexios Zavras <alexios.zavras@...el.com>,
Thomas Gleixner <tglx@...utronix.de>,
Changbin Du <changbin.du@...el.com>,
Eric Saint-Etienne <eric.saint.etienne@...cle.com>,
Konstantin Khlebnikov <khlebnikov@...dex-team.ru>,
Thomas Richter <tmricht@...ux.ibm.com>,
Alexey Budankov <alexey.budankov@...ux.intel.com>,
linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org
Cc: Leo Yan <leo.yan@...aro.org>
Subject: [PATCH v1 05/11] perf trace: Smatch: Fix potential NULL pointer dereference
Based on the following report from Smatch, fix the potential
NULL pointer dereference check.
tools/perf/builtin-trace.c:1044
thread_trace__new() error: we previously assumed 'ttrace' could be
null (see line 1041).
tools/perf/builtin-trace.c
1037 static struct thread_trace *thread_trace__new(void)
1038 {
1039 struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace));
1040
1041 if (ttrace)
1042 ttrace->files.max = -1;
1043
1044 ttrace->syscall_stats = intlist__new(NULL);
^^^^^^^^
1045
1046 return ttrace;
1047 }
This patch directly returns NULL when fail to allocate memory for
ttrace; this can avoid potential NULL pointer dereference.
Signed-off-by: Leo Yan <leo.yan@...aro.org>
---
tools/perf/builtin-trace.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index f3532b081b31..874d78890c60 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1038,9 +1038,10 @@ static struct thread_trace *thread_trace__new(void)
{
struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace));
- if (ttrace)
- ttrace->files.max = -1;
+ if (ttrace == NULL)
+ return NULL;
+ ttrace->files.max = -1;
ttrace->syscall_stats = intlist__new(NULL);
return ttrace;
--
2.17.1
Powered by blists - more mailing lists