Skip to contentSkip to conversation

hw/virtio/vhost-backend: Fix Coverity CID 1432871

PATCH In review Philippe Mathieu-Daudé 2 participants 2 messages Nov 3, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/virtio/vhost-backend: Fix Coverity CID 1432871

Fix uninitialized value issues reported by Coverity:

Field 'msg.reserved' is uninitialized when calling write().

While the 'struct vhost_msg' does not have a 'reserved' field, we still initialize it to have the two parts of the function consistent.

Reported-by Coverity (CID 1432864: UNINIT)
Fixes c471ad0e9bd ("vhost_net: device IOTLB support")

---
v2: comment 'struct vhost_msg' is also initialized (Peter)

---
 hw/virtio/vhost-backend.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/vhost-backend.c +2 -2
index 88c8ecc9e03..222bbcc62de 100644
@@ -257,7 +257,7 @@ static int vhost_kernel_send_device_iotlb_msg(struct vhost_dev *dev,
                                               struct vhost_iotlb_msg *imsg)
 {
     if (dev->backend_cap & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2)) {
-        struct vhost_msg_v2 msg;
+        struct vhost_msg_v2 msg = {};
 
         msg.type = VHOST_IOTLB_MSG_V2;
         msg.iotlb = *imsg;
@@ -267,7 +267,7 @@ static int vhost_kernel_send_device_iotlb_msg(struct vhost_dev *dev,
             return -EFAULT;
         }
     } else {
-        struct vhost_msg msg;
+        struct vhost_msg msg = {};
 
         msg.type = VHOST_IOTLB_MSG;
         msg.iotlb = *imsg;
Signature · 1 line
2.26.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 12 lines · Philippe Mathieu-Daudé

Fix uninitialized value issues reported by Coverity:

Field 'msg.reserved' is uninitialized when calling write().

While the 'struct vhost_msg' does not have a 'reserved' field, we still initialize it to have the two parts of the function consistent.

Reported-by Coverity (CID 1432864: UNINIT)
Fixes c471ad0e9bd ("vhost_net: device IOTLB support")
Quoted 5 lines

---
v2: comment 'struct vhost_msg' is also initialized (Peter)
---
hw/virtio/vhost-backend.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 27 lines
hw/virtio/vhost-backend.c +2 -2
index 88c8ecc9e03..222bbcc62de 100644
@@ -257,7 +257,7 @@ static int vhost_kernel_send_device_iotlb_msg(struct vhost_dev *dev,
                                              struct vhost_iotlb_msg *imsg)
 {
    if (dev->backend_cap & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2)) {
-        struct vhost_msg_v2 msg;
+        struct vhost_msg_v2 msg = {};
 
        msg.type = VHOST_IOTLB_MSG_V2;
        msg.iotlb = *imsg;
@@ -267,7 +267,7 @@ static int vhost_kernel_send_device_iotlb_msg(struct vhost_dev *dev,
            return -EFAULT;
        }
    } else {
-        struct vhost_msg msg;
+        struct vhost_msg msg = {};
 
        msg.type = VHOST_IOTLB_MSG;
        msg.iotlb = *imsg;
Signature · 1 line
2.26.2