From: Adrian Hunter Date: Tue, 9 Aug 2022 08:07:00 +0000 (+0300) Subject: perf parse-events: Fix segfault when event parser gets an error X-Git-Tag: v5.15.73~915 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5958ef867b9d75a66d819114e6a196ed10957097;p=platform%2Fkernel%2Flinux-rpi.git perf parse-events: Fix segfault when event parser gets an error commit 2e828582b81f5bc76a4fe8e7812df259ab208302 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: 43eb05d066795bdf ("perf tests: Support 'Track with sched_switch' test for hybrid") Signed-off-by: Adrian Hunter Cc: Ian Rogers Cc: Jin Yao Cc: Jiri Olsa Cc: Namhyung Kim Link: https://lore.kernel.org/r/20220809080702.6921-2-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 3bfe099..b93a36f 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -196,9 +196,12 @@ static int tp_event_has_id(const char *dir_path, struct dirent *evt_dir) void parse_events__handle_error(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: @@ -224,6 +227,11 @@ void parse_events__handle_error(struct parse_events_error *err, int idx, break; } err->num_errors++; + return; + +out_free: + free(str); + free(help); } struct tracepoint_path *tracepoint_id_to_path(u64 config)