vhost: fix null pointer dereference
authorMarcin Kerlin <marcinx.kerlin@intel.com>
Wed, 15 Jun 2016 09:47:22 +0000 (11:47 +0200)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Wed, 22 Jun 2016 07:47:12 +0000 (09:47 +0200)
Return value of function get_device() is not checking before
dereference. Fix this problem by adding checking condition.

Coverity issue: 119262

Fixes: 77d20126b4c2 ("vhost-user: handle message to enable vring")

Signed-off-by: Marcin Kerlin <marcinx.kerlin@intel.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
lib/librte_vhost/vhost_user/virtio-net-user.c

index c21ec6b..64a6ec4 100644 (file)
@@ -335,9 +335,13 @@ user_get_vring_base(int vid, struct vhost_vring_state *state)
 int
 user_set_vring_enable(int vid, struct vhost_vring_state *state)
 {
-       struct virtio_net *dev = get_device(vid);
+       struct virtio_net *dev;
        int enable = (int)state->num;
 
+       dev = get_device(vid);
+       if (dev == NULL)
+               return -1;
+
        RTE_LOG(INFO, VHOST_CONFIG,
                "set queue enable: %d to qp idx: %d\n",
                enable, state->index);