diff mbox series

[for,3.1,4/4] virtio: qemu_get_virtqueue_element fail rather than assert

Message ID 20180716173743.133393-5-dgilbert@redhat.com
State New
Headers show
Series virtio migration load path | expand

Commit Message

Dr. David Alan Gilbert July 16, 2018, 5:37 p.m. UTC
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Make it return NULL rather than assert.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 hw/virtio/virtio.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

Comments

Cornelia Huck July 17, 2018, 9:16 a.m. UTC | #1
On Mon, 16 Jul 2018 18:37:43 +0100
"Dr. David Alan Gilbert (git)" <dgilbert@redhat.com> wrote:

$SUBJECT reads a bit odd without a 'make', but it is already long...

> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> Make it return NULL rather than assert.
> 
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
>  hw/virtio/virtio.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>
diff mbox series

Patch

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index d4e4d98b59..aedd390240 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1037,13 +1037,12 @@  void *qemu_get_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, size_t sz)
 
     qemu_get_buffer(f, (uint8_t *)&data, sizeof(VirtQueueElementOld));
 
-    /* TODO: teach all callers that this can fail, and return failure instead
-     * of asserting here.
-     * This is just one thing (there are probably more) that must be
-     * fixed before we can allow NDEBUG compilation.
-     */
-    assert(ARRAY_SIZE(data.in_addr) >= data.in_num);
-    assert(ARRAY_SIZE(data.out_addr) >= data.out_num);
+    if (data.in_num > ARRAY_SIZE(data.in_addr) ||
+        data.out_num > ARRAY_SIZE(data.out_addr)) {
+        error_report("%s: Bad index: in=%d out=%d",
+                    __func__, data.in_num, data.out_num);
+        return NULL;
+    }
 
     elem = virtqueue_alloc_element(sz, data.out_num, data.in_num);
     elem->index = data.index;