From nobody Fri May 3 22:44:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1491465203702582.669766845627; Thu, 6 Apr 2017 00:53:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E807A7AEB6; Thu, 6 Apr 2017 07:53:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 971DC94452; Thu, 6 Apr 2017 07:53:21 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CF3A24BB75; Thu, 6 Apr 2017 07:53:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v367rHP6001914 for ; Thu, 6 Apr 2017 03:53:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id EBB5EA4089; Thu, 6 Apr 2017 07:53:17 +0000 (UTC) Received: from inaba.usersys.redhat.com.redhat.com (ovpn-204-84.brq.redhat.com [10.40.204.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73209A4075; Thu, 6 Apr 2017 07:53:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E807A7AEB6 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E807A7AEB6 From: Andrea Bolognani To: libvir-list@redhat.com Date: Thu, 6 Apr 2017 09:53:11 +0200 Message-Id: <1491465191-23912-1-git-send-email-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: pkrempa@redhat.com Subject: [libvirt] [PATCH v2] storage: Avoid leak in virStorageUtilGlusterExtractPoolSources() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 06 Apr 2017 07:53:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The contents of volname would be leaked if the function were to be passed an invalid pooltype by the caller. Make sure the memory is released instead. --- Changes from v1: * use VIR_STEAL_PTR() instead of open-coding it. src/storage/storage_util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 7cc125a..8e25984 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2846,7 +2846,7 @@ virStorageUtilGlusterExtractPoolSources(const char *h= ost, xmlXPathContextPtr ctxt =3D NULL; xmlNodePtr *nodes =3D NULL; virStoragePoolSource *src =3D NULL; - char *volname; + char *volname =3D NULL; size_t i; int nnodes; int ret =3D -1; @@ -2871,12 +2871,11 @@ virStorageUtilGlusterExtractPoolSources(const char = *host, =20 if (pooltype =3D=3D VIR_STORAGE_POOL_NETFS) { src->format =3D VIR_STORAGE_POOL_NETFS_GLUSTERFS; - src->dir =3D volname; + VIR_STEAL_PTR(src->dir, volname); } else if (pooltype =3D=3D VIR_STORAGE_POOL_GLUSTER) { - src->name =3D volname; - if (VIR_STRDUP(src->dir, "/") < 0) goto cleanup; + VIR_STEAL_PTR(src->name, volname); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unsupported gluster lookup")); @@ -2894,6 +2893,7 @@ virStorageUtilGlusterExtractPoolSources(const char *h= ost, ret =3D nnodes; =20 cleanup: + VIR_FREE(volname); VIR_FREE(nodes); xmlXPathFreeContext(ctxt); xmlFreeDoc(doc); --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list