From: Michail Tatas <michail.tatas@gmail.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
namhyung@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
james.clark@linaro.org
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] perf ftrace: Fix leak in parse_filter_event
Date: Mon, 3 Aug 2026 10:50:04 +0300 [thread overview]
Message-ID: <anBILHWZfxku7OWq@michalis-linux> (raw)
strsep() advances the pointer given to it. After the loop s is
either NULL (on success) or points mid buffer (early exit if malloc
fails) so the original buffer is never freed properly.
Fix by adding a tmp pointer for use by strsep and free the original
pointer
Signed-off-by: Michail Tatas <michail.tatas@gmail.com>
---
tools/perf/builtin-ftrace.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index f7126196b092..4f881a40c311 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -1607,14 +1607,15 @@ static int parse_filter_event(const struct option *opt, const char *str,
{
struct list_head *head = opt->value;
struct filter_entry *entry;
- char *s, *p;
+ char *s, *p, *tmp;
int ret = -ENOMEM;
s = strdup(str);
if (s == NULL)
return -ENOMEM;
- while ((p = strsep(&s, ",")) != NULL) {
+ tmp = s;
+ while ((p = strsep(&tmp, ",")) != NULL) {
entry = malloc(sizeof(*entry) + strlen(p) + 1);
if (entry == NULL)
goto out;
--
2.43.0
next reply other threads:[~2026-08-03 7:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 7:50 Michail Tatas [this message]
2026-08-04 17:04 ` [PATCH] perf ftrace: Fix leak in parse_filter_event Namhyung Kim
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=anBILHWZfxku7OWq@michalis-linux \
--to=michail.tatas@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.