From nobody Mon Apr 29 06:19:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518486876327939.2440602731534; Mon, 12 Feb 2018 17:54:36 -0800 (PST) Received: from localhost ([::1]:53039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elPne-0008Qv-8d for importer@patchew.org; Mon, 12 Feb 2018 20:54:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elPmW-0007kL-85 for qemu-devel@nongnu.org; Mon, 12 Feb 2018 20:53:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elPmV-0002VV-FC for qemu-devel@nongnu.org; Mon, 12 Feb 2018 20:53:16 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45610 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1elPmP-0002OS-PO; Mon, 12 Feb 2018 20:53:09 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4574F8163C52; Tue, 13 Feb 2018 01:52:59 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-89.pek2.redhat.com [10.72.12.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECA8D10075FA; Tue, 13 Feb 2018 01:52:49 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 13 Feb 2018 09:52:40 +0800 Message-Id: <20180213015240.9352-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 13 Feb 2018 01:52:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 13 Feb 2018 01:52:59 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2] block/nvme: fix Coverity reports X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, Fam Zheng , f4bug@amsat.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini 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 Signed-off-by: Fam Zheng --- 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); =20 - nvme_identify(bs, namespace, errp); + nvme_identify(bs, namespace, &local_err); if (local_err) { error_propagate(errp, local_err); ret =3D -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_S= IZE); + } + 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 =3D NULL; =20 sysfs_link =3D g_strdup_printf("/sys/bus/pci/devices/%s/iommu_group", = device); - sysfs_group =3D g_malloc(PATH_MAX); + sysfs_group =3D g_malloc0(PATH_MAX); if (readlink(sysfs_link, sysfs_group, PATH_MAX - 1) =3D=3D -1) { error_setg_errno(errp, errno, "Failed to find iommu group sysfs pa= th"); goto out; --=20 2.14.3