From: Adrian Hunter <adrian.hunter@intel.com>
To: Ian Rogers <irogers@google.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] perf parse-events: Fix segfault when event parser gets an error
Date: Tue, 19 Jul 2022 13:45:56 +0300 [thread overview]
Message-ID: <5d7c9f8a-76f7-7c77-62a3-f94adc083497@intel.com> (raw)
In-Reply-To: <CAP-5=fUaDsuYxQRkqWFThX3Su2me-caXxdQqJd0WH-dx-yRaug@mail.gmail.com>
On 19/07/22 04:10, Ian Rogers wrote:
> On Tue, Jul 12, 2022 at 4:28 AM Adrian Hunter <adrian.hunter@intel.com> wrote:
>>
>> parse_events() is often called with parse_events_error set to NULL.
>> Make parse_events_error__handle() not segfault in that case.
>>
>> Fixes: 43eb05d06679 ("perf tests: Support 'Track with sched_switch' test for hybrid")
>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
>> ---
>> tools/perf/util/parse-events.c | 14 +++++++++++---
>> 1 file changed, 11 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
>> index 7ed235740431..700c95eafd62 100644
>> --- a/tools/perf/util/parse-events.c
>> +++ b/tools/perf/util/parse-events.c
>> @@ -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;
>
>
> It feels like a simpler invariant (as done elsewhere) to have the
> caller always pass err and then in the caller to call
> parse_events_error__exit. Any reason for behavior change?
This is a bug fix. More complicated changes can be done separately,
if desired, but it is wrong to segfault here in any case.
>
> Thanks,
> Ian
>
>> }
>> switch (err->num_errors) {
>> case 0:
>> @@ -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
>> --
>> 2.25.1
>>
next prev parent reply other threads:[~2022-07-19 10:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 11:28 [PATCH 0/2] perf tests: Fix Track with sched_switch test for hybrid case Adrian Hunter
2022-07-12 11:28 ` [PATCH 1/2] perf parse-events: Fix segfault when event parser gets an error Adrian Hunter
2022-07-19 1:10 ` Ian Rogers
2022-07-19 10:45 ` Adrian Hunter [this message]
2022-07-12 11:28 ` [PATCH 2/2] perf tests: Fix Track with sched_switch test for hybrid case Adrian Hunter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5d7c9f8a-76f7-7c77-62a3-f94adc083497@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@kernel.org \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®