From: Ian Rogers <irogers@google.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-devel@vger.kernel.org, Ian Rogers <irogers@google.com>
Subject: [PATCH] libtraceevent: Fix leaks and NULL check in process_int_dynamic_array()
Date: Mon, 28 Sep 2026 12:11:55 -0700 [thread overview]
Message-ID: <20260928191155.3712558-1-irogers@google.com> (raw)
process_int_dynamic_array() reads the name of the array's field into
token, but only frees it on the "out" error path, so each
__print_dynamic_array() parsed leaks the name. The kernel's syscall events
use it for user space buffers, such as write's buf. The early return, when
the first argument isn't a name, leaks the token too, and unlike the other
error path it doesn't set *tok to NULL.
Also check the result of alloc_arg() rather than arg, which can't be NULL,
so that an allocation failure is reported rather than dereferenced.
Found with LeakSanitizer running perf trace.
Fixes: 3f9655198727 ("libtraceevent: Add support for __print_dynamic_array() macro")
Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@google.com>
---
src/event-parse.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/event-parse.c b/src/event-parse.c
index 4bd5c1b..14e1b91 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -3473,8 +3473,11 @@ process_int_dynamic_array(struct tep_event *event, struct tep_print_arg *arg, ch
* the index into where the array starts.
*/
type = read_token(event->tep, &token);
- if (type != TEP_EVENT_ITEM)
+ if (type != TEP_EVENT_ITEM) {
+ free_token(token);
+ *tok = NULL;
return TEP_EVENT_ERROR;
+ }
/* Find the field */
field = tep_find_field(event, token);
@@ -3490,7 +3493,7 @@ process_int_dynamic_array(struct tep_event *event, struct tep_print_arg *arg, ch
goto out;
arg->int_array.field = alloc_arg();
- if (!arg) {
+ if (!arg->int_array.field) {
do_warning_event(event, "%s: not enough memory!", __func__);
goto out;
}
@@ -3499,6 +3502,7 @@ process_int_dynamic_array(struct tep_event *event, struct tep_print_arg *arg, ch
arg->int_array.field->dynarray.field = field;
arg->int_array.field->dynarray.index = 0;
+ free_token(token);
return read_token_item(event->tep, tok);
out:
free_token(token);
base-commit: 51d47b0eb2b40d4273fb461782fe9a01db0f901c
--
2.56.0.rc1.315.gc6ed9934b7-goog
reply other threads:[~2026-09-28 19:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260928191155.3712558-1-irogers@google.com \
--to=irogers@google.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.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