Skip to content

Commit

Permalink
perf parse-events: Fix segfault when event parser gets an error
Browse files Browse the repository at this point in the history
commit 2e82858 upstream.

parse_events() is often called with parse_events_error set to NULL.
Make parse_events_error__handle() not segfault in that case.

A subsequent patch changes to avoid passing NULL in the first place.

Fixes: 43eb05d ("perf tests: Support 'Track with sched_switch' test for hybrid")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20220809080702.6921-2-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
ahunter6 authored and gregkh committed Aug 25, 2022
1 parent 8f89e5c commit 129fe9d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tools/perf/util/parse-events.c
Expand Up @@ -2391,9 +2391,12 @@ void parse_events_error__exit(struct parse_events_error *err)
void parse_events_error__handle(struct parse_events_error *err, int idx,
char *str, char *help)
{
if (WARN(!str, "WARNING: failed to provide error string\n")) {
free(help);
return;
if (WARN(!str, "WARNING: failed to provide error string\n"))
goto out_free;
if (!err) {
/* Assume caller does not want message printed */
pr_debug("event syntax error: %s\n", str);
goto out_free;
}
switch (err->num_errors) {
case 0:
Expand All @@ -2419,6 +2422,11 @@ void parse_events_error__handle(struct parse_events_error *err, int idx,
break;
}
err->num_errors++;
return;

out_free:
free(str);
free(help);
}

#define MAX_WIDTH 1000
Expand Down

0 comments on commit 129fe9d

Please sign in to comment.