* [Qemu-devel] [PATCH v2] block/nvme: fix Coverity reports
@ 2018-02-09 16:20 Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2018-02-09 16:20 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-block
1) string not null terminated in sysfs_find_group_file
2) NULL pointer dereference and incorrect Error* usage in nvme_init.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
block/nvme.c | 10 +++++++---
util/vfio-helpers.c | 2 +-
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index e9d0e218fc..a62c92a190 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -644,7 +644,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier,
false, nvme_handle_event, nvme_poll_cb);
- nvme_identify(bs, namespace, errp);
+ nvme_identify(bs, namespace, &local_err);
if (local_err) {
error_propagate(errp, local_err);
ret = -EIO;
@@ -665,8 +665,12 @@ fail_queue:
nvme_free_queue_pair(bs, s->queues[0]);
fail:
g_free(s->queues);
- qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);
- qemu_vfio_close(s->vfio);
+ if (s->regs) {
+ qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);
+ }
+ if (s->vfio) {
+ qemu_vfio_close(s->vfio);
+ }
event_notifier_cleanup(&s->irq_notifier);
return ret;
}
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index f478b68400..006674c916 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -104,7 +104,7 @@ static char *sysfs_find_group_file(const char *device, Error **errp)
char *path = NULL;
sysfs_link = g_strdup_printf("/sys/bus/pci/devices/%s/iommu_group", device);
- sysfs_group = g_malloc(PATH_MAX);
+ sysfs_group = g_malloc0(PATH_MAX);
if (readlink(sysfs_link, sysfs_group, PATH_MAX - 1) == -1) {
error_setg_errno(errp, errno, "Failed to find iommu group sysfs path");
goto out;
--
2.14.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [Qemu-devel] [PATCH v2] block/nvme: fix Coverity reports
@ 2018-02-13 1:52 Fam Zheng
0 siblings, 0 replies; 2+ messages in thread
From: Fam Zheng @ 2018-02-13 1:52 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, pbonzini, Fam Zheng, f4bug, qemu-block
From: Paolo Bonzini <pbonzini@redhat.com>
1) string not null terminated in sysfs_find_group_file
2) NULL pointer dereference and dead local variable in nvme_init.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
---
v2: Fix error path.
---
block/nvme.c | 10 +++++++---
util/vfio-helpers.c | 2 +-
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index e9d0e218fc..a62c92a190 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -644,7 +644,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier,
false, nvme_handle_event, nvme_poll_cb);
- nvme_identify(bs, namespace, errp);
+ nvme_identify(bs, namespace, &local_err);
if (local_err) {
error_propagate(errp, local_err);
ret = -EIO;
@@ -665,8 +665,12 @@ fail_queue:
nvme_free_queue_pair(bs, s->queues[0]);
fail:
g_free(s->queues);
- qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);
- qemu_vfio_close(s->vfio);
+ if (s->regs) {
+ qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);
+ }
+ if (s->vfio) {
+ qemu_vfio_close(s->vfio);
+ }
event_notifier_cleanup(&s->irq_notifier);
return ret;
}
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index f478b68400..006674c916 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -104,7 +104,7 @@ static char *sysfs_find_group_file(const char *device, Error **errp)
char *path = NULL;
sysfs_link = g_strdup_printf("/sys/bus/pci/devices/%s/iommu_group", device);
- sysfs_group = g_malloc(PATH_MAX);
+ sysfs_group = g_malloc0(PATH_MAX);
if (readlink(sysfs_link, sysfs_group, PATH_MAX - 1) == -1) {
error_setg_errno(errp, errno, "Failed to find iommu group sysfs path");
goto out;
--
2.14.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-02-13 1:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-13 1:52 [Qemu-devel] [PATCH v2] block/nvme: fix Coverity reports Fam Zheng
-- strict thread matches above, loose matches on Subject: below --
2018-02-09 16:20 Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).