diff mbox series

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

Message ID 20190321194127.4ac47d99@gandalf.local.home (mailing list archive)
State Accepted
Commit 0f03474a17ac401fdd3c7d35ec7f111160dd4e9b
Headers show
Series trace-cmd: Have tracecmd_msg_data_send() return zero on zero size | expand

Commit Message

Steven Rostedt March 21, 2019, 11:41 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

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.

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

Comments

Slavomir Kaslev March 22, 2019, 11:49 a.m. UTC | #1
On Thu, 2019-03-21 at 19:41 -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> 
> 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.
> 
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>  tracecmd/trace-msg.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c
> index 51d0ac8b..382bd766 100644
> --- a/tracecmd/trace-msg.c
> +++ b/tracecmd/trace-msg.c
> @@ -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);

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

Reviewed-by: Slavomir Kaslev <kaslevs@vmware.com>

-- Slavi
Steven Rostedt March 22, 2019, 12:17 p.m. UTC | #2
On Fri, 22 Mar 2019 11:49:29 +0000
Slavomir Kaslev <kaslevs@vmware.com> wrote:

> > diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c
> > index 51d0ac8b..382bd766 100644
> > --- a/tracecmd/trace-msg.c
> > +++ b/tracecmd/trace-msg.c
> > @@ -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);  
> 
> Nice catch. Definitely a latent bug waiting for someone to step on it.
> 
> Reviewed-by: Slavomir Kaslev <kaslevs@vmware.com>

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
diff mbox series

Patch

diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c
index 51d0ac8b..382bd766 100644
--- a/tracecmd/trace-msg.c
+++ b/tracecmd/trace-msg.c
@@ -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);