Skip to contentSkip to conversation

trace-cmd: Have tracecmd_msg_data_send() return zero on zero size

PATCH In review Steven Rostedt 2 participants 3 messages Mar 21, 2019 – Mar 22, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd: Have tracecmd_msg_data_send() return zero on zero size

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

If tracecmd_msg_data_send() is passed a size of zero, the loop is not entered, nothing is sent, but the ret variable is not initialized and garbage can be sent out. The option code can call this with a size of zero, which can cause an error report.

Just don't do anything in this case, and return a success.

---
 tracecmd/trace-msg.c | 4 ++++
 1 file changed, 4 insertions(+)
tracecmd/trace-msg.c +4 -0
index 51d0ac8b..382bd766 100644
@@ -590,6 +590,10 @@ int tracecmd_msg_data_send(struct tracecmd_msg_handle *msg_handle,
 	int ret;
 	int count = 0;
 
+	/* Don't bother doing anything if there's nothing to do */
+	if (!size)
+		return 0;
+
 	tracecmd_msg_init(MSG_SEND_DATA, &msg);
 
 	msg.buf = malloc(MSG_MAX_DATA_LEN);
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Steven Rostedt

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

If tracecmd_msg_data_send() is passed a size of zero, the loop is not entered, nothing is sent, but the ret variable is not initialized and garbage can be sent out. The option code can call this with a size of zero,
which can cause an error report.

Just don't do anything in this case, and return a success.

---
 tracecmd/trace-msg.c | 4 ++++
 1 file changed, 4 insertions(+)
tracecmd/trace-msg.c +4 -0
index 51d0ac8b..382bd766 100644
@@ -590,6 +590,10 @@ int tracecmd_msg_data_send(struct
 tracecmd_msg_handle *msg_handle,
 	int ret;
 	int count = 0;
 
+	/* Don't bother doing anything if there's nothing to do */
+	if (!size)
+		return 0;
+
 	tracecmd_msg_init(MSG_SEND_DATA, &msg);
 
Quoted 1 line

msg.buf = malloc(MSG_MAX_DATA_LEN);

Nice catch. Definitely a latent bug waiting for someone to step on it.

-- Slavi

#2 lore raw
Quoted 15 lines · On Fri, 22 Mar 2019 11:49:29 +0000 Slavomir Kaslev <[email protected]> wrote:
Quoted 15 lines
tracecmd/trace-msg.c +4 -0
index 51d0ac8b..382bd766 100644
@@ -590,6 +590,10 @@ int tracecmd_msg_data_send(struct
 tracecmd_msg_handle *msg_handle,
 	int ret;
 	int count = 0;
 
+	/* Don't bother doing anything if there's nothing to do */
+	if (!size)
+		return 0;
+
 	tracecmd_msg_init(MSG_SEND_DATA, &msg);
 
Quoted 5 lines
Quoted 1 line

msg.buf = malloc(MSG_MAX_DATA_LEN);

Nice catch. Definitely a latent bug waiting for someone to step on it.

Yeah, it tripped me up, as I had a box that crashed because of it. Delaying the finishing of the testing. Which I'm rerunning now.

-- Steve