Skip to contentSkip to conversation

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

PATCH New Steven Rostedt 1 participant 1 message Jul 29, 2022

lore
Share & tools
lore
#0 lore raw

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

From: "Steven Rostedt (Google)" <[email protected]>

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.

---
 lib/trace-cmd/trace-msg.c | 2 ++
 1 file changed, 2 insertions(+)
lib/trace-cmd/trace-msg.c +2 -0
index 9c26401a..342d03e4 100644
@@ -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)
Signature · 1 line
2.35.1