提交 0ba1f531 编写于 作者: F Fam Zheng 提交者: Paolo Bonzini

virtio-scsi: Fix num_queue input validation

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: NFam Zheng <famz@redhat.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 fb7b5c0d
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册