Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Fix parse_events_error dereferences

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>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
a6ced2be bb78ce7d

+6 -2
+2
tools/perf/util/parse-events.c
··· 1659 1659 { 1660 1660 struct parse_events_error *err = data->error; 1661 1661 1662 + if (!err) 1663 + return; 1662 1664 err->idx = idx; 1663 1665 err->str = strdup(str); 1664 1666 WARN_ONCE(!err->str, "WARNING: failed to allocate error string");
+4 -2
tools/perf/util/parse-events.y
··· 389 389 if (parse_events_add_tracepoint(list, &data->idx, $1, $3)) { 390 390 struct parse_events_error *error = data->error; 391 391 392 - error->idx = @1.first_column; 393 - error->str = strdup("unknown tracepoint"); 392 + if (error) { 393 + error->idx = @1.first_column; 394 + error->str = strdup("unknown tracepoint"); 395 + } 394 396 return -1; 395 397 } 396 398 $$ = list;