[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-363bbaef63ffebcc745239fe80a953ebb5ac9ec9@git.kernel.org>
Date: Sat, 13 Jul 2019 03:55:59 -0700
From: tip-bot for Leo Yan <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: yao.jin@...ux.intel.com, tmricht@...ux.ibm.com,
linux@...musvillemoes.dk, khlebnikov@...dex-team.ru,
alexander.shishkin@...ux.intel.com, acme@...hat.com,
suzuki.poulose@....com, peterz@...radead.org,
adrian.hunter@...el.com, davem@...emloft.net, hpa@...or.com,
linux-kernel@...r.kernel.org, alexey.budankov@...ux.intel.com,
changbin.du@...el.com, jolsa@...nel.org, ak@...ux.intel.com,
mathieu.poirier@...aro.org, namhyung@...nel.org,
alexios.zavras@...el.com, mingo@...nel.org, songliubraving@...com,
tglx@...utronix.de, leo.yan@...aro.org, dave@...olabs.net,
eric.saint.etienne@...cle.com
Subject: [tip:perf/urgent] perf map: Fix potential NULL pointer dereference
found by smatch tool
Commit-ID: 363bbaef63ffebcc745239fe80a953ebb5ac9ec9
Gitweb: https://git.kernel.org/tip/363bbaef63ffebcc745239fe80a953ebb5ac9ec9
Author: Leo Yan <leo.yan@...aro.org>
AuthorDate: Tue, 2 Jul 2019 18:34:16 +0800
Committer: Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Tue, 9 Jul 2019 09:33:55 -0300
perf map: Fix potential NULL pointer dereference found by smatch tool
Based on the following report from Smatch, fix the potential NULL
pointer dereference check.
tools/perf/util/map.c:479
map__fprintf_srccode() error: we previously assumed 'state' could be
null (see line 466)
tools/perf/util/map.c
465 /* Avoid redundant printing */
466 if (state &&
467 state->srcfile &&
468 !strcmp(state->srcfile, srcfile) &&
469 state->line == line) {
470 free(srcfile);
471 return 0;
472 }
473
474 srccode = find_sourceline(srcfile, line, &len);
475 if (!srccode)
476 goto out_free_line;
477
478 ret = fprintf(fp, "|%-8d %.*s", line, len, srccode);
479 state->srcfile = srcfile;
^^^^^^^
480 state->line = line;
^^^^^^^
This patch validates 'state' pointer before access its elements.
Signed-off-by: Leo Yan <leo.yan@...aro.org>
Acked-by: Jiri Olsa <jolsa@...nel.org>
Cc: Adrian Hunter <adrian.hunter@...el.com>
Cc: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Cc: Alexey Budankov <alexey.budankov@...ux.intel.com>
Cc: Alexios Zavras <alexios.zavras@...el.com>
Cc: Andi Kleen <ak@...ux.intel.com>
Cc: Changbin Du <changbin.du@...el.com>
Cc: David S. Miller <davem@...emloft.net>
Cc: Davidlohr Bueso <dave@...olabs.net>
Cc: Eric Saint-Etienne <eric.saint.etienne@...cle.com>
Cc: Jin Yao <yao.jin@...ux.intel.com>
Cc: Konstantin Khlebnikov <khlebnikov@...dex-team.ru>
Cc: Mathieu Poirier <mathieu.poirier@...aro.org>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Rasmus Villemoes <linux@...musvillemoes.dk>
Cc: Song Liu <songliubraving@...com>
Cc: Suzuki Poulouse <suzuki.poulose@....com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Thomas Richter <tmricht@...ux.ibm.com>
Cc: linux-arm-kernel@...ts.infradead.org
Fixes: dd2e18e9ac20 ("perf tools: Support 'srccode' output")
Link: http://lkml.kernel.org/r/20190702103420.27540-8-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
tools/perf/util/map.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 6fce983c6115..5f87975d2562 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -476,8 +476,11 @@ int map__fprintf_srccode(struct map *map, u64 addr,
goto out_free_line;
ret = fprintf(fp, "|%-8d %.*s", line, len, srccode);
- state->srcfile = srcfile;
- state->line = line;
+
+ if (state) {
+ state->srcfile = srcfile;
+ state->line = line;
+ }
return ret;
out_free_line:
Powered by blists - more mailing lists