diff mbox series

[v2,1/3] tests: vhost-user-test: initialize 'fd' in chr_read

Message ID 20181215120353.82786-2-liq3ea@163.com
State New
Headers show
Series vhost-user-test fix | expand

Commit Message

Li Qiang Dec. 15, 2018, 12:03 p.m. UTC
Currently when processing VHOST_USER_SET_VRING_CALL
if 'qemu_chr_fe_get_msgfds' get no fd, the 'fd' will
be a stack uninitialized value.

Signed-off-by: Li Qiang <liq3ea@163.com>
---
 tests/vhost-user-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Thomas Huth Jan. 2, 2019, 1:50 p.m. UTC | #1
On 2018-12-15 13:03, Li Qiang wrote:
> Currently when processing VHOST_USER_SET_VRING_CALL
> if 'qemu_chr_fe_get_msgfds' get no fd, the 'fd' will
> be a stack uninitialized value.
> 
> Signed-off-by: Li Qiang <liq3ea@163.com>
> ---
>  tests/vhost-user-test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
> index 45d58d8ea2..86039e61e0 100644
> --- a/tests/vhost-user-test.c
> +++ b/tests/vhost-user-test.c
> @@ -309,7 +309,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
>      CharBackend *chr = &s->chr;
>      VhostUserMsg msg;
>      uint8_t *p = (uint8_t *) &msg;
> -    int fd;
> +    int fd = -1;
>  
>      if (s->test_fail) {
>          qemu_chr_fe_disconnect(chr);
> 

Shouldn't we also rather check the return code of
qemu_chr_fe_get_msgfds() ? Anyway, initializing fd to -1 here sounds
like a good idea, so:

Reviewed-by: Thomas Huth <thuth@redhat.com>
Michael S. Tsirkin Jan. 2, 2019, 2:55 p.m. UTC | #2
On Wed, Jan 02, 2019 at 02:50:50PM +0100, Thomas Huth wrote:
> On 2018-12-15 13:03, Li Qiang wrote:
> > Currently when processing VHOST_USER_SET_VRING_CALL
> > if 'qemu_chr_fe_get_msgfds' get no fd, the 'fd' will
> > be a stack uninitialized value.
> > 
> > Signed-off-by: Li Qiang <liq3ea@163.com>
> > ---
> >  tests/vhost-user-test.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
> > index 45d58d8ea2..86039e61e0 100644
> > --- a/tests/vhost-user-test.c
> > +++ b/tests/vhost-user-test.c
> > @@ -309,7 +309,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
> >      CharBackend *chr = &s->chr;
> >      VhostUserMsg msg;
> >      uint8_t *p = (uint8_t *) &msg;
> > -    int fd;
> > +    int fd = -1;
> >  
> >      if (s->test_fail) {
> >          qemu_chr_fe_disconnect(chr);
> > 
> 
> Shouldn't we also rather check the return code of
> qemu_chr_fe_get_msgfds() ? Anyway, initializing fd to -1 here sounds
> like a good idea, so:
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Li Qiang Jan. 3, 2019, 4:23 a.m. UTC | #3
Thomas Huth <thuth@redhat.com> 于2019年1月2日周三 下午9:50写道:

> On 2018-12-15 13:03, Li Qiang wrote:
> > Currently when processing VHOST_USER_SET_VRING_CALL
> > if 'qemu_chr_fe_get_msgfds' get no fd, the 'fd' will
> > be a stack uninitialized value.
> >
> > Signed-off-by: Li Qiang <liq3ea@163.com>
> > ---
> >  tests/vhost-user-test.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
> > index 45d58d8ea2..86039e61e0 100644
> > --- a/tests/vhost-user-test.c
> > +++ b/tests/vhost-user-test.c
> > @@ -309,7 +309,7 @@ static void chr_read(void *opaque, const uint8_t
> *buf, int size)
> >      CharBackend *chr = &s->chr;
> >      VhostUserMsg msg;
> >      uint8_t *p = (uint8_t *) &msg;
> > -    int fd;
> > +    int fd = -1;
> >
> >      if (s->test_fail) {
> >          qemu_chr_fe_disconnect(chr);
> >
>
> Shouldn't we also rather check the return code of
> qemu_chr_fe_get_msgfds() ?


Agree, there are several places need to do this. I will send out a patch
later.

Thanks,
Li Qiang


> Anyway, initializing fd to -1 here sounds
> like a good idea, so:
>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
>
diff mbox series

Patch

diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
index 45d58d8ea2..86039e61e0 100644
--- a/tests/vhost-user-test.c
+++ b/tests/vhost-user-test.c
@@ -309,7 +309,7 @@  static void chr_read(void *opaque, const uint8_t *buf, int size)
     CharBackend *chr = &s->chr;
     VhostUserMsg msg;
     uint8_t *p = (uint8_t *) &msg;
-    int fd;
+    int fd = -1;
 
     if (s->test_fail) {
         qemu_chr_fe_disconnect(chr);