[PATCH 15/25] tools lib traceevent: Handle NULL comm name

From: Arnaldo Carvalho de Melo
Date: Tue Mar 24 2015 - 12:21:04 EST


From: Josef Bacik <jbacik@xxxxxx>

It is possible that a pid has no associated comm attached to it, although it
can still be passed to pevent_register_comm().

But if comm is NULL, it will cause strdup() to segfault. To prevent this
from happening, if comm is NULL use the default "<...>" name for the
pid.

Signed-off-by: Josef Bacik <jbacik@xxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Link: http://lkml.kernel.org/r/20150324135922.549965495@xxxxxxxxxxx
Link: http://lkml.kernel.org/p/1403799732-30308-1-git-send-email-jbacik@xxxxxx
Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/lib/traceevent/event-parse.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 8e5e4f6137bb..31d4e7da191c 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -304,7 +304,10 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid)
if (!item)
return -1;

- item->comm = strdup(comm);
+ if (comm)
+ item->comm = strdup(comm);
+ else
+ item->comm = strdup("<...>");
if (!item->comm) {
free(item);
return -1;
--
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/