devices: add null check after map_guest_mem calls 91/20991/3
authorSteven Luong <sluong@cisco.com>
Wed, 31 Jul 2019 23:01:14 +0000 (16:01 -0700)
committerDave Barach <openvpp@barachs.net>
Fri, 2 Aug 2019 20:32:14 +0000 (20:32 +0000)
map_guest_mem may return null. Coverity complains about calls
without checking its return. Simple stuff.

Type: fix

Signed-off-by: Steven Luong <sluong@cisco.com>
Change-Id: I0626115f4951a88f23d9792f0232fb57c132fbc2

src/vnet/devices/virtio/vhost_user_input.c

index 22f79e6..488764b 100644 (file)
@@ -585,10 +585,24 @@ vhost_user_if_input (vlib_main_t * vm,
              data_offset = 0;
            }
          hdr = map_guest_mem (vui, desc_table[current].addr, &map_hint);
+         if (PREDICT_FALSE (hdr == 0))
+           {
+             vlib_error_count (vm, node->node_index,
+                               VHOST_USER_INPUT_FUNC_ERROR_MMAP_FAIL, 1);
+             goto out;
+           }
          b_data = (u8 *) hdr + data_offset;
          if (indirect)
-           hdr = map_guest_mem (vui, desc_table[desc_current].addr,
-                                &map_hint);
+           {
+             hdr = map_guest_mem (vui, desc_table[desc_current].addr,
+                                  &map_hint);
+             if (PREDICT_FALSE (hdr == 0))
+               {
+                 vlib_error_count (vm, node->node_index,
+                                   VHOST_USER_INPUT_FUNC_ERROR_MMAP_FAIL, 1);
+                 goto out;
+               }
+           }
          vhost_user_handle_rx_offload (b_head, b_data, &hdr->hdr);
        }