linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "linux-trace-devel@vger.kernel.org"  <linux-trace-devel@vger.kernel.org>
Cc: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Subject: [PATCH] trace-cmd: Initialize option list earlier in create_file_fd()
Date: Mon, 21 Jun 2021 22:18:14 -0400	[thread overview]
Message-ID: <20210621221814.200894db@oasis.local.home> (raw)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

The error paths of create_file_fd() after the handle is allocated, jumps
to the out_free label. This will call tracecmd_output_close(), which will
clean up the allocated tracecmd_output handle. This includes the options
list. But there's two error paths that will jump to out_free before the
options list is initialized. If an error occurs in one of these two
locations, then walking the option list will cause a segfault.

Initialize the option list immediately after the allocation of the handle
and before any of the error paths that jump to out_free.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-output.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index b3d0fe7e..78a25350 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -938,6 +938,8 @@ create_file_fd(int fd, struct tracecmd_input *ihandle,
 		return NULL;
 	memset(handle, 0, sizeof(*handle));
 
+	list_head_init(&handle->options);
+
 	handle->fd = fd;
 	if (tracing_dir) {
 		handle->tracing_dir = strdup(tracing_dir);
@@ -950,8 +952,6 @@ create_file_fd(int fd, struct tracecmd_input *ihandle,
 	if (select_file_version(handle, ihandle))
 		goto out_free;
 
-	list_head_init(&handle->options);
-
 	buf[0] = 23;
 	buf[1] = 8;
 	buf[2] = 68;
-- 
2.29.2


                 reply	other threads:[~2021-06-22  2:18 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=20210621221814.200894db@oasis.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tstoyanov@vmware.com \
    /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;
as well as URLs for NNTP newsgroup(s).