diff mbox series

trace-cmd libs: Initialize msg to NULL tracecmd_msg_read_data()

Message ID 20220729164850.460886bb@rorschach.local.home (mailing list archive)
State Accepted
Commit ef8a8d7a748ac7937742d1dddd3207c1c2401d5d
Headers show
Series trace-cmd libs: Initialize msg to NULL tracecmd_msg_read_data() | expand

Commit Message

Steven Rostedt July 29, 2022, 8:48 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If there are no parameters passed to the guest agent, then the loop
inside tracecmd_msg_read_data() will not iterate and the msg variable
will be accessed (freed) without being initailized causing a possible
SEGFAULT.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-msg.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c
index 9c26401a..342d03e4 100644
--- a/lib/trace-cmd/trace-msg.c
+++ b/lib/trace-cmd/trace-msg.c
@@ -980,6 +980,8 @@  int tracecmd_msg_read_data(struct tracecmd_msg_handle *msg_handle, int ofd)
 	ssize_t s;
 	int ret;
 
+	memset(&msg, 0, sizeof(msg));
+
 	while (!tracecmd_msg_done(msg_handle)) {
 		n = read_msg_data(msg_handle, &msg);
 		if (n <= 0)