2014-06-26 16:22:38

by Josef Bacik

[permalink] [raw]
Subject: [PATCH] trace-cmd: handle NULL comm name in .dat file

Sometimes the comm field in the trace.dat file can be empty which means that the
event parsing stuff can pass a NULL into pevent_register_comm. To fix this just
check if we are NULL and generate a bogus comm name for that PID. This keeps us
from segfaulting. Thanks,

Signed-off-by: Josef Bacik <[email protected]>
---
event-parse.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/event-parse.c b/event-parse.c
index 18b3587..00304fe 100644
--- a/event-parse.c
+++ b/event-parse.c
@@ -303,7 +303,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;
--
2.0.0


2014-06-27 20:21:28

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] trace-cmd: handle NULL comm name in .dat file

On Thu, 26 Jun 2014 09:22:12 -0700
Josef Bacik <[email protected]> wrote:

> Sometimes the comm field in the trace.dat file can be empty which means that the
> event parsing stuff can pass a NULL into pevent_register_comm. To fix this just
> check if we are NULL and generate a bogus comm name for that PID. This keeps us
> from segfaulting. Thanks,
>
> Signed-off-by: Josef Bacik <[email protected]>

Applied, thanks!

-- Steve

> ---
> event-parse.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/event-parse.c b/event-parse.c
> index 18b3587..00304fe 100644
> --- a/event-parse.c
> +++ b/event-parse.c
> @@ -303,7 +303,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;