From nobody Thu Apr 25 21:36:15 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1520346482896362.80802794226474; Tue, 6 Mar 2018 06:28:02 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42B18C0587D2; Tue, 6 Mar 2018 14:28:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 18FC7600C9; Tue, 6 Mar 2018 14:28:01 +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 C4D4C4A470; Tue, 6 Mar 2018 14:28:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w26ERwF4023048 for ; Tue, 6 Mar 2018 09:27:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id C08122024CAB; Tue, 6 Mar 2018 14:27:58 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AB1A2024CAD; Tue, 6 Mar 2018 14:27:58 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 6 Mar 2018 15:27:10 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 1/6] util: storage: Simplify error handling in virStorageAuthDefParseXML 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 06 Mar 2018 14:28:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Unify the cleanup and error paths and simplify the code flow by removing some unnecessary variables. Signed-off-by: Peter Krempa Reviewed-by: John Ferlan --- src/util/virstoragefile.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index d1972d6d1d..3d17911297 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1813,20 +1813,18 @@ static virStorageAuthDefPtr virStorageAuthDefParseXML(xmlXPathContextPtr ctxt) { virStorageAuthDefPtr authdef =3D NULL; + virStorageAuthDefPtr ret =3D NULL; xmlNodePtr secretnode =3D NULL; - char *username =3D NULL; char *authtype =3D NULL; if (VIR_ALLOC(authdef) < 0) return NULL; - if (!(username =3D virXPathString("string(./@username)", ctxt))) { + if (!(authdef->username =3D virXPathString("string(./@username)", ctxt= ))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing username for auth")); - goto error; + goto cleanup; } - authdef->username =3D username; - username =3D NULL; authdef->authType =3D VIR_STORAGE_AUTH_TYPE_NONE; authtype =3D virXPathString("string(./@type)", ctxt); @@ -1837,15 +1835,14 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt) if ((authdef->authType =3D virStorageAuthTypeFromString(authtype))= < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown auth type '%s'"), authtype); - goto error; + goto cleanup; } - VIR_FREE(authtype); } if (!(secretnode =3D virXPathNode("./secret ", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing element in auth")); - goto error; + goto cleanup; } /* Used by the domain disk xml parsing in order to ensure the @@ -1858,15 +1855,15 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt) authdef->secrettype =3D virXMLPropString(secretnode, "type"); if (virSecretLookupParseSecret(secretnode, &authdef->seclookupdef) < 0) - goto error; + goto cleanup; - return authdef; + VIR_STEAL_PTR(ret, authdef); - error: + cleanup: VIR_FREE(authtype); - VIR_FREE(username); virStorageAuthDefFree(authdef); - return NULL; + + return ret; } --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 21:36:15 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1520346486574505.1942738932662; Tue, 6 Mar 2018 06:28:06 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A89D687623; Tue, 6 Mar 2018 14:28:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6DCEC5C8AA; Tue, 6 Mar 2018 14:28:04 +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 2E99D181A878; Tue, 6 Mar 2018 14:28:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w26ERxpe023054 for ; Tue, 6 Mar 2018 09:27:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7AB85200AE93; Tue, 6 Mar 2018 14:27:59 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05C082024CAD; Tue, 6 Mar 2018 14:27:58 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 6 Mar 2018 15:27:11 +0100 Message-Id: <3678f3c8a62d0821255e39d2d066a6668b340c7d.1520346349.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 2/6] util: storage: Sanitize parsing of disk auth XMLs 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 06 Mar 2018 14:28:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Pass in the XPath context as we do in all other places rather than allocating a new one. Signed-off-by: Peter Krempa Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 21 ++++++++++++--------- src/conf/storage_conf.c | 2 +- src/util/virstoragefile.c | 32 ++++++++------------------------ src/util/virstoragefile.h | 3 ++- 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a248d73de3..a8be0db7e4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7218,7 +7218,8 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr = sourcenode, static int virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode, - virDomainHostdevSubsysSCSIPtr d= ef) + virDomainHostdevSubsysSCSIPtr d= ef, + xmlXPathContextPtr ctxt) { int ret =3D -1; int auth_secret_usage =3D -1; @@ -7259,7 +7260,7 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr= sourcenode, while (cur !=3D NULL) { if (cur->type =3D=3D XML_ELEMENT_NODE && virXMLNodeNameEqual(cur, "auth")) { - if (!(authdef =3D virStorageAuthDefParse(sourcenode->doc, cur)= )) + if (!(authdef =3D virStorageAuthDefParse(cur, ctxt))) goto cleanup; if ((auth_secret_usage =3D virSecretUsageTypeFromString(authdef->secrettype)) < 0) { @@ -7288,7 +7289,8 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr= sourcenode, static int virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode, - virDomainHostdevSubsysSCSIPtr scsisr= c) + virDomainHostdevSubsysSCSIPtr scsisr= c, + xmlXPathContextPtr ctxt) { char *protocol =3D NULL; int ret =3D -1; @@ -7305,7 +7307,7 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sour= cenode, } if (scsisrc->protocol =3D=3D VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISC= SI) - ret =3D virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scs= isrc); + ret =3D virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scs= isrc, ctxt); else ret =3D virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsi= src); @@ -7550,7 +7552,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: - if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, scsisrc) < 0) + if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, scsisrc, ctx= t) < 0) goto error; break; @@ -8540,7 +8542,8 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, static int virDomainDiskSourceAuthParse(xmlNodePtr node, - virStorageAuthDefPtr *authdefsrc) + virStorageAuthDefPtr *authdefsrc, + xmlXPathContextPtr ctxt) { xmlNodePtr child; virStorageAuthDefPtr authdef; @@ -8549,7 +8552,7 @@ virDomainDiskSourceAuthParse(xmlNodePtr node, if (child->type =3D=3D XML_ELEMENT_NODE && virXMLNodeNameEqual(child, "auth")) { - if (!(authdef =3D virStorageAuthDefParse(node->doc, child))) + if (!(authdef =3D virStorageAuthDefParse(child, ctxt))) return -1; *authdefsrc =3D authdef; @@ -8653,7 +8656,7 @@ virDomainDiskSourceParse(xmlNodePtr node, goto cleanup; } - if (virDomainDiskSourceAuthParse(node, &src->auth) < 0) + if (virDomainDiskSourceAuthParse(node, &src->auth, ctxt) < 0) goto cleanup; if (virDomainDiskSourceEncryptionParse(node, &src->encryption) < 0) @@ -9401,7 +9404,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } - if (!(authdef =3D virStorageAuthDefParse(node->doc, cur))) + if (!(authdef =3D virStorageAuthDefParse(cur, ctxt))) goto error; } else if (virXMLNodeNameEqual(cur, "iotune")) { if (virDomainDiskDefIotuneParse(def, ctxt) < 0) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index b9135722c1..f1f469d462 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -527,7 +527,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, } if ((authnode =3D virXPathNode("./auth", ctxt))) { - if (!(authdef =3D virStorageAuthDefParse(node->doc, authnode))) + if (!(authdef =3D virStorageAuthDefParse(authnode, ctxt))) goto cleanup; if (authdef->authType =3D=3D VIR_STORAGE_AUTH_TYPE_NONE) { diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 3d17911297..67b9ec71ac 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1809,16 +1809,20 @@ virStorageAuthDefCopy(const virStorageAuthDef *src) } -static virStorageAuthDefPtr -virStorageAuthDefParseXML(xmlXPathContextPtr ctxt) +virStorageAuthDefPtr +virStorageAuthDefParse(xmlNodePtr node, + xmlXPathContextPtr ctxt) { + xmlNodePtr saveNode =3D ctxt->node; virStorageAuthDefPtr authdef =3D NULL; virStorageAuthDefPtr ret =3D NULL; xmlNodePtr secretnode =3D NULL; char *authtype =3D NULL; + ctxt->node =3D node; + if (VIR_ALLOC(authdef) < 0) - return NULL; + goto cleanup; if (!(authdef->username =3D virXPathString("string(./@username)", ctxt= ))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -1862,32 +1866,12 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt) cleanup: VIR_FREE(authtype); virStorageAuthDefFree(authdef); + ctxt->node =3D saveNode; return ret; } -virStorageAuthDefPtr -virStorageAuthDefParse(xmlDocPtr xml, xmlNodePtr root) -{ - xmlXPathContextPtr ctxt =3D NULL; - virStorageAuthDefPtr authdef =3D NULL; - - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); - goto cleanup; - } - - ctxt->node =3D root; - authdef =3D virStorageAuthDefParseXML(ctxt); - - cleanup: - xmlXPathFreeContext(ctxt); - return authdef; -} - - void virStorageAuthDefFormat(virBufferPtr buf, virStorageAuthDefPtr authdef) diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 0095cd1387..596746ccb7 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -366,7 +366,8 @@ int virStorageFileGetSCSIKey(const char *path, void virStorageAuthDefFree(virStorageAuthDefPtr def); virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src); -virStorageAuthDefPtr virStorageAuthDefParse(xmlDocPtr xml, xmlNodePtr root= ); +virStorageAuthDefPtr virStorageAuthDefParse(xmlNodePtr node, + xmlXPathContextPtr ctxt); void virStorageAuthDefFormat(virBufferPtr buf, virStorageAuthDefPtr authde= f); virSecurityDeviceLabelDefPtr --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 21:36:15 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152034649213224.797626660235096; Tue, 6 Mar 2018 06:28:12 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0CD8757D9; Tue, 6 Mar 2018 14:28:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 883B361F55; Tue, 6 Mar 2018 14:28:09 +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 ED75B4A475; Tue, 6 Mar 2018 14:28:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w26ES05O023066 for ; Tue, 6 Mar 2018 09:28:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id 359982024CAE; Tue, 6 Mar 2018 14:28:00 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id B45A12024CAB; Tue, 6 Mar 2018 14:27:59 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 6 Mar 2018 15:27:12 +0100 Message-Id: <7463c79e81846344a58a101d3a0d60485b3d199b.1520346349.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 3/6] conf: Replace virDomainDiskSourceAuthParse by an XPath query 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 06 Mar 2018 14:28:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Remove the rather bulky function in favor of an XPath query. Signed-off-by: Peter Krempa Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a8be0db7e4..31b2590a13 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8540,30 +8540,6 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, } -static int -virDomainDiskSourceAuthParse(xmlNodePtr node, - virStorageAuthDefPtr *authdefsrc, - xmlXPathContextPtr ctxt) -{ - xmlNodePtr child; - virStorageAuthDefPtr authdef; - - for (child =3D node->children; child; child =3D child->next) { - if (child->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(child, "auth")) { - - if (!(authdef =3D virStorageAuthDefParse(child, ctxt))) - return -1; - - *authdefsrc =3D authdef; - return 0; - } - } - - return 0; -} - - static int virDomainDiskSourceEncryptionParse(xmlNodePtr node, virStorageEncryptionPtr *encryptionsrc) @@ -8627,6 +8603,7 @@ virDomainDiskSourceParse(xmlNodePtr node, { int ret =3D -1; xmlNodePtr saveNode =3D ctxt->node; + xmlNodePtr tmp; ctxt->node =3D node; @@ -8656,7 +8633,8 @@ virDomainDiskSourceParse(xmlNodePtr node, goto cleanup; } - if (virDomainDiskSourceAuthParse(node, &src->auth, ctxt) < 0) + if ((tmp =3D virXPathNode("./auth", ctxt)) && + !(src->auth =3D virStorageAuthDefParse(tmp, ctxt))) goto cleanup; if (virDomainDiskSourceEncryptionParse(node, &src->encryption) < 0) --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 21:36:15 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1520346486522835.2382196979532; Tue, 6 Mar 2018 06:28:06 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E2E47ECFF; Tue, 6 Mar 2018 14:28:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 655D25C88A; Tue, 6 Mar 2018 14:28:04 +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 2C0304A474; Tue, 6 Mar 2018 14:28:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w26ES1qA023071 for ; Tue, 6 Mar 2018 09:28:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id E54F7200AE93; Tue, 6 Mar 2018 14:28:00 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F9B62026DFD; Tue, 6 Mar 2018 14:28:00 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 6 Mar 2018 15:27:13 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 4/6] util: storageencryption: Refactor cleanup section in virStorageEncryptionParseXML 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 06 Mar 2018 14:28:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The function used the 'cleanup' label only in error cases. This patch makes the code pass the cleanup label in every case and removes few unnecessary VIR_FREEs. Signed-off-by: Peter Krempa Reviewed-by: John Ferlan --- src/util/virstorageencryption.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/util/virstorageencryption.c b/src/util/virstorageencryptio= n.c index 116a2358ae..f3de5ff7a7 100644 --- a/src/util/virstorageencryption.c +++ b/src/util/virstorageencryption.c @@ -246,13 +246,14 @@ static virStorageEncryptionPtr virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) { xmlNodePtr *nodes =3D NULL; - virStorageEncryptionPtr ret; + virStorageEncryptionPtr encdef =3D NULL; + virStorageEncryptionPtr ret =3D NULL; char *format_str =3D NULL; int n; size_t i; - if (VIR_ALLOC(ret) < 0) - return NULL; + if (VIR_ALLOC(encdef) < 0) + goto cleanup; if (!(format_str =3D virXPathString("string(./@format)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -260,60 +261,57 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) goto cleanup; } - if ((ret->format =3D + if ((encdef->format =3D virStorageEncryptionFormatTypeFromString(format_str)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown volume encryption format type %s"), format_str); goto cleanup; } - VIR_FREE(format_str); if ((n =3D virXPathNodeSet("./secret", ctxt, &nodes)) < 0) goto cleanup; if (n > 0) { - if (VIR_ALLOC_N(ret->secrets, n) < 0) + if (VIR_ALLOC_N(encdef->secrets, n) < 0) goto cleanup; - ret->nsecrets =3D n; + encdef->nsecrets =3D n; for (i =3D 0; i < n; i++) { - if (!(ret->secrets[i] =3D + if (!(encdef->secrets[i] =3D virStorageEncryptionSecretParse(ctxt, nodes[i]))) goto cleanup; } - VIR_FREE(nodes); } - if (ret->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { + if (encdef->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { xmlNodePtr tmpnode; if ((tmpnode =3D virXPathNode("./cipher[1]", ctxt))) { - if (virStorageEncryptionInfoParseCipher(tmpnode, &ret->encinfo= ) < 0) + if (virStorageEncryptionInfoParseCipher(tmpnode, &encdef->enci= nfo) < 0) goto cleanup; } if ((tmpnode =3D virXPathNode("./ivgen[1]", ctxt))) { /* If no cipher node, then fail */ - if (!ret->encinfo.cipher_name) { + if (!encdef->encinfo.cipher_name) { virReportError(VIR_ERR_XML_ERROR, "%s", _("ivgen element found, but cipher is miss= ing")); goto cleanup; } - if (virStorageEncryptionInfoParseIvgen(tmpnode, &ret->encinfo)= < 0) + if (virStorageEncryptionInfoParseIvgen(tmpnode, &encdef->encin= fo) < 0) goto cleanup; } } - - return ret; + VIR_STEAL_PTR(ret, encdef); cleanup: VIR_FREE(format_str); VIR_FREE(nodes); - virStorageEncryptionFree(ret); - return NULL; + virStorageEncryptionFree(encdef); + return ret; } virStorageEncryptionPtr --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 21:36:15 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1520346494836264.7282141612337; Tue, 6 Mar 2018 06:28:14 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 939A185376; Tue, 6 Mar 2018 14:28:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 583D6177F8; Tue, 6 Mar 2018 14:28:13 +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 EA807181A881; Tue, 6 Mar 2018 14:28:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w26ES1Av023088 for ; Tue, 6 Mar 2018 09:28:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id A07D42024CAE; Tue, 6 Mar 2018 14:28:01 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B0022024CAD; Tue, 6 Mar 2018 14:28:01 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 6 Mar 2018 15:27:14 +0100 Message-Id: <35876bf476d4f401b43a95943b0ed41df387064c.1520346349.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 5/6] util: storage: Sanitize parsing of disk encryption XMLs 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 06 Mar 2018 14:28:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Pass in the XPath context as we do in all other places rather than allocating a new one. Signed-off-by: Peter Krempa Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 9 +++++---- src/conf/storage_conf.c | 3 +-- src/util/virstorageencryption.c | 37 ++++++++----------------------------- src/util/virstorageencryption.h | 4 ++-- 4 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 31b2590a13..f5bc6148a2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8542,7 +8542,8 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, static int virDomainDiskSourceEncryptionParse(xmlNodePtr node, - virStorageEncryptionPtr *encryptionsrc) + virStorageEncryptionPtr *encryptionsrc, + xmlXPathContextPtr ctxt) { xmlNodePtr child; virStorageEncryptionPtr encryption =3D NULL; @@ -8551,7 +8552,7 @@ virDomainDiskSourceEncryptionParse(xmlNodePtr node, if (child->type =3D=3D XML_ELEMENT_NODE && virXMLNodeNameEqual(child, "encryption")) { - if (!(encryption =3D virStorageEncryptionParseNode(node->doc, = child))) + if (!(encryption =3D virStorageEncryptionParseNode(child, ctxt= ))) return -1; *encryptionsrc =3D encryption; @@ -8637,7 +8638,7 @@ virDomainDiskSourceParse(xmlNodePtr node, !(src->auth =3D virStorageAuthDefParse(tmp, ctxt))) goto cleanup; - if (virDomainDiskSourceEncryptionParse(node, &src->encryption) < 0) + if (virDomainDiskSourceEncryptionParse(node, &src->encryption, ctxt) <= 0) goto cleanup; if (virDomainDiskSourcePrivateDataParse(ctxt, src, flags, xmlopt) < 0) @@ -9408,7 +9409,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } - if (!(encryption =3D virStorageEncryptionParseNode(node->doc, = cur))) + if (!(encryption =3D virStorageEncryptionParseNode(cur, ctxt))) goto error; } else if (!serial && virXMLNodeNameEqual(cur, "serial")) { diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index f1f469d462..5036ab9ef8 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1209,8 +1209,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, node =3D virXPathNode("./target/encryption", ctxt); if (node !=3D NULL) { - ret->target.encryption =3D virStorageEncryptionParseNode(ctxt->doc, - node); + ret->target.encryption =3D virStorageEncryptionParseNode(node, ctx= t); if (ret->target.encryption =3D=3D NULL) goto error; } diff --git a/src/util/virstorageencryption.c b/src/util/virstorageencryptio= n.c index f3de5ff7a7..77c46faf8e 100644 --- a/src/util/virstorageencryption.c +++ b/src/util/virstorageencryption.c @@ -242,9 +242,11 @@ virStorageEncryptionInfoParseIvgen(xmlNodePtr info_nod= e, } -static virStorageEncryptionPtr -virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) +virStorageEncryptionPtr +virStorageEncryptionParseNode(xmlNodePtr node, + xmlXPathContextPtr ctxt) { + xmlNodePtr saveNode =3D ctxt->node; xmlNodePtr *nodes =3D NULL; virStorageEncryptionPtr encdef =3D NULL; virStorageEncryptionPtr ret =3D NULL; @@ -252,6 +254,8 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) int n; size_t i; + ctxt->node =3D node; + if (VIR_ALLOC(encdef) < 0) goto cleanup; @@ -311,34 +315,9 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) VIR_FREE(format_str); VIR_FREE(nodes); virStorageEncryptionFree(encdef); - return ret; -} - -virStorageEncryptionPtr -virStorageEncryptionParseNode(xmlDocPtr xml, xmlNodePtr root) -{ - xmlXPathContextPtr ctxt =3D NULL; - virStorageEncryptionPtr enc =3D NULL; - - if (STRNEQ((const char *) root->name, "encryption")) { - virReportError(VIR_ERR_XML_ERROR, - "%s", _("unknown root element for volume " - "encryption information")); - goto cleanup; - } + ctxt->node =3D saveNode; - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); - goto cleanup; - } - - ctxt->node =3D root; - enc =3D virStorageEncryptionParseXML(ctxt); - - cleanup: - xmlXPathFreeContext(ctxt); - return enc; + return ret; } diff --git a/src/util/virstorageencryption.h b/src/util/virstorageencryptio= n.h index 42f990c494..1c0a39c32e 100644 --- a/src/util/virstorageencryption.h +++ b/src/util/virstorageencryption.h @@ -83,8 +83,8 @@ virStorageEncryptionPtr virStorageEncryptionCopy(const vi= rStorageEncryption *src void virStorageEncryptionFree(virStorageEncryptionPtr enc); -virStorageEncryptionPtr virStorageEncryptionParseNode(xmlDocPtr xml, - xmlNodePtr root); +virStorageEncryptionPtr virStorageEncryptionParseNode(xmlNodePtr node, + xmlXPathContextPtr c= txt); int virStorageEncryptionFormat(virBufferPtr buf, virStorageEncryptionPtr enc); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 21:36:15 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1520346490872668.5070555796656; Tue, 6 Mar 2018 06:28:10 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8394B7655E; Tue, 6 Mar 2018 14:28:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2113260176; Tue, 6 Mar 2018 14:28:09 +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 86F3E181A87E; Tue, 6 Mar 2018 14:28:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w26ES2Nn023093 for ; Tue, 6 Mar 2018 09:28:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5B5F8200AE93; Tue, 6 Mar 2018 14:28:02 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA3692024CAD; Tue, 6 Mar 2018 14:28:01 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 6 Mar 2018 15:27:15 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 6/6] conf: Replace virDomainDiskSourceEncryptionParse by an XPath query 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 06 Mar 2018 14:28:10 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Remove the rather bulky function in favor of an XPath query. Signed-off-by: Peter Krempa Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f5bc6148a2..c8d756c45d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8540,30 +8540,6 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, } -static int -virDomainDiskSourceEncryptionParse(xmlNodePtr node, - virStorageEncryptionPtr *encryptionsrc, - xmlXPathContextPtr ctxt) -{ - xmlNodePtr child; - virStorageEncryptionPtr encryption =3D NULL; - - for (child =3D node->children; child; child =3D child->next) { - if (child->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(child, "encryption")) { - - if (!(encryption =3D virStorageEncryptionParseNode(child, ctxt= ))) - return -1; - - *encryptionsrc =3D encryption; - return 0; - } - } - - return 0; -} - - static int virDomainDiskSourcePrivateDataParse(xmlXPathContextPtr ctxt, virStorageSourcePtr src, @@ -8638,7 +8614,8 @@ virDomainDiskSourceParse(xmlNodePtr node, !(src->auth =3D virStorageAuthDefParse(tmp, ctxt))) goto cleanup; - if (virDomainDiskSourceEncryptionParse(node, &src->encryption, ctxt) <= 0) + if ((tmp =3D virXPathNode("./encryption", ctxt)) && + !(src->encryption =3D virStorageEncryptionParseNode(tmp, ctxt))) goto cleanup; if (virDomainDiskSourcePrivateDataParse(ctxt, src, flags, xmlopt) < 0) --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list