]> xenbits.xensource.com Git - qemu-upstream-4.6-testing.git/commitdiff
virtio-scsi: Fix num_queue input validation
authorFam Zheng <famz@redhat.com>
Fri, 31 Oct 2014 03:04:31 +0000 (11:04 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 31 Oct 2014 10:29:02 +0000 (11:29 +0100)
We need to count the ctrlq and eventq, and also cleanup before
returning. Besides, the format string should be unsigned.

The number could never be less than zero.

Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/scsi/virtio-scsi.c

index 235c2053da4f0a768d460814a0b6ebeca330b54c..fdcacfd79abbe809e68801364a4733abcee75b71 100644 (file)
@@ -804,10 +804,11 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
     virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI,
                 sizeof(VirtIOSCSIConfig));
 
-    if (s->conf.num_queues <= 0 || s->conf.num_queues > VIRTIO_PCI_QUEUE_MAX) {
-        error_setg(errp, "Invalid number of queues (= %" PRId32 "), "
+    if (s->conf.num_queues == 0 ||
+            s->conf.num_queues > VIRTIO_PCI_QUEUE_MAX - 2) {
+        error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
                          "must be a positive integer less than %d.",
-                   s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX);
+                   s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX - 2);
         virtio_cleanup(vdev);
         return;
     }