perf tools: Fix parse_events_error dereferences
authorAdrian Hunter <adrian.hunter@intel.com>
Tue, 19 May 2015 13:05:44 +0000 (16:05 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 27 May 2015 15:21:43 +0000 (12:21 -0300)
Parse errors can be reported in struct parse_events_error but the
pointer passed is optional and can be NULL.  Ensure it is not NULL
before dereferencing it.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Link: http://lkml.kernel.org/r/1432040746-1755-4-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/parse-events.c
tools/perf/util/parse-events.y

index 78032d887c1ae5e0b5debe0ead2a210fffcb5c7f..2a4d1ec028464757d6723bbd08c2d0ce0a010a14 100644 (file)
@@ -1659,6 +1659,8 @@ void parse_events_evlist_error(struct parse_events_evlist *data,
 {
        struct parse_events_error *err = data->error;
 
+       if (!err)
+               return;
        err->idx = idx;
        err->str = strdup(str);
        WARN_ONCE(!err->str, "WARNING: failed to allocate error string");
index 3d11e00243e38a74229562d8eccef3bbe9340ec2..591905a02b926b6029447a372f2e5f7b7d34864a 100644 (file)
@@ -389,8 +389,10 @@ PE_NAME ':' PE_NAME
        if (parse_events_add_tracepoint(list, &data->idx, $1, $3)) {
                struct parse_events_error *error = data->error;
 
-               error->idx = @1.first_column;
-               error->str = strdup("unknown tracepoint");
+               if (error) {
+                       error->idx = @1.first_column;
+                       error->str = strdup("unknown tracepoint");
+               }
                return -1;
        }
        $$ = list;