[PATCH v2] perf tools: Check for null when copying nsinfo.

From: Benno Evers
Date: Fri Aug 10 2018 - 09:36:39 EST


The argument to nsinfo__copy() was assumed to be valid, but some code paths
exist that will lead to NULL being passed.

In particular, running 'perf script -D' on a perf.data file containing an
PERF_RECORD_MMAP event associating the '[vdso]' dso with pid 0 earlier in
the event stream will lead to a segfault.

Since all calling code is already checking for a non-null return value,
just return NULL for this case as well.

Acked-by: Namhyung Kim <namhyung@xxxxxxxxxx>
Signed-off-by: Benno Evers <bevers@xxxxxxxxxxxxxx>
---
Changes from v1:
Added Signed-off-by line.

tools/perf/util/namespaces.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/namespaces.c b/tools/perf/util/namespaces.c
index 5be021701f34..cf8bd123cf73 100644
--- a/tools/perf/util/namespaces.c
+++ b/tools/perf/util/namespaces.c
@@ -139,6 +139,9 @@ struct nsinfo *nsinfo__copy(struct nsinfo *nsi)
{
struct nsinfo *nnsi;

+ if (nsi == NULL)
+ return NULL;
+
nnsi = calloc(1, sizeof(*nnsi));
if (nnsi != NULL) {
nnsi->pid = nsi->pid;
--
2.17.1