From nobody Tue May 7 07:45: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 1532976466487675.0757478626908; Mon, 30 Jul 2018 11:47:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5099230832EA; Mon, 30 Jul 2018 18:47:33 +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 1BF9D10D7C3E; Mon, 30 Jul 2018 18:47:33 +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 B47854A469; Mon, 30 Jul 2018 18:47:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UIl3r2000482 for ; Mon, 30 Jul 2018 14:47:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3CA6AD0FC2; Mon, 30 Jul 2018 18:47:03 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-84.phx2.redhat.com [10.3.116.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 749D5D0CE4 for ; Mon, 30 Jul 2018 18:46:54 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 14:46:38 -0400 Message-Id: <20180730184648.5059-2-jferlan@redhat.com> In-Reply-To: <20180730184648.5059-1-jferlan@redhat.com> References: <20180730184648.5059-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/11] conf: Add @flags to Storage Pool Def processing 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 30 Jul 2018 18:47:44 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a @flags argument when parsing the storage pool definition via the virStoragePoolDefParse{XML|Node|String|File} API's as this will allow us to in the future make parsing decisions based on the @flags. Signed-off-by: John Ferlan --- src/conf/domain_conf.c | 2 +- src/conf/storage_conf.c | 25 ++++++++++++++++--------- src/conf/storage_conf.h | 12 ++++++++---- src/conf/virstorageobj.c | 4 ++-- src/phyp/phyp_driver.c | 2 +- src/storage/storage_driver.c | 4 ++-- src/test/test_driver.c | 6 +++--- tests/storagebackendsheepdogtest.c | 4 ++-- tests/storagepoolxml2xmltest.c | 2 +- tests/storagevolxml2argvtest.c | 4 ++-- tests/storagevolxml2xmltest.c | 2 +- 11 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index eff8af20e7..42b55f01d4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30183,7 +30183,7 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPt= r def) if (!(poolxml =3D virStoragePoolGetXMLDesc(pool, 0))) goto cleanup; =20 - if (!(pooldef =3D virStoragePoolDefParseString(poolxml))) + if (!(pooldef =3D virStoragePoolDefParseString(poolxml, 0))) goto cleanup; =20 def->src->srcpool->pooltype =3D pooldef->type; diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 5036ab9ef8..e5d35cd254 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -671,7 +671,8 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt, =20 =20 virStoragePoolDefPtr -virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) +virStoragePoolDefParseXML(xmlXPathContextPtr ctxt, + unsigned int flags) { virStoragePoolOptionsPtr options; virStoragePoolDefPtr ret; @@ -680,6 +681,8 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) char *uuid =3D NULL; char *target_path =3D NULL; =20 + virCheckFlags(0, NULL); + if (VIR_ALLOC(ret) < 0) return NULL; =20 @@ -818,7 +821,8 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) =20 virStoragePoolDefPtr virStoragePoolDefParseNode(xmlDocPtr xml, - xmlNodePtr root) + xmlNodePtr root, + unsigned int flags) { xmlXPathContextPtr ctxt =3D NULL; virStoragePoolDefPtr def =3D NULL; @@ -838,7 +842,7 @@ virStoragePoolDefParseNode(xmlDocPtr xml, } =20 ctxt->node =3D root; - def =3D virStoragePoolDefParseXML(ctxt); + def =3D virStoragePoolDefParseXML(ctxt, flags); cleanup: xmlXPathFreeContext(ctxt); return def; @@ -847,13 +851,14 @@ virStoragePoolDefParseNode(xmlDocPtr xml, =20 static virStoragePoolDefPtr virStoragePoolDefParse(const char *xmlStr, - const char *filename) + const char *filename, + unsigned int flags) { virStoragePoolDefPtr ret =3D NULL; xmlDocPtr xml; =20 if ((xml =3D virXMLParse(filename, xmlStr, _("(storage_pool_definition= )")))) { - ret =3D virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml)); + ret =3D virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml),= flags); xmlFreeDoc(xml); } =20 @@ -862,16 +867,18 @@ virStoragePoolDefParse(const char *xmlStr, =20 =20 virStoragePoolDefPtr -virStoragePoolDefParseString(const char *xmlStr) +virStoragePoolDefParseString(const char *xmlStr, + unsigned int flags) { - return virStoragePoolDefParse(xmlStr, NULL); + return virStoragePoolDefParse(xmlStr, NULL, flags); } =20 =20 virStoragePoolDefPtr -virStoragePoolDefParseFile(const char *filename) +virStoragePoolDefParseFile(const char *filename, + unsigned int flags) { - return virStoragePoolDefParse(NULL, filename); + return virStoragePoolDefParse(NULL, filename, flags); } =20 =20 diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 15dfd8becf..d6886ad6ca 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -236,17 +236,21 @@ struct _virStoragePoolSourceList { }; =20 virStoragePoolDefPtr -virStoragePoolDefParseXML(xmlXPathContextPtr ctxt); +virStoragePoolDefParseXML(xmlXPathContextPtr ctxt, + unsigned int flags); =20 virStoragePoolDefPtr -virStoragePoolDefParseString(const char *xml); +virStoragePoolDefParseString(const char *xml, + unsigned int flags); =20 virStoragePoolDefPtr -virStoragePoolDefParseFile(const char *filename); +virStoragePoolDefParseFile(const char *filename, + unsigned int flags); =20 virStoragePoolDefPtr virStoragePoolDefParseNode(xmlDocPtr xml, - xmlNodePtr root); + xmlNodePtr root, + unsigned int flags); =20 char * virStoragePoolDefFormat(virStoragePoolDefPtr def); diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index e66b2ebfb2..47209fae96 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -1110,7 +1110,7 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def; virStoragePoolObjPtr obj; =20 - if (!(def =3D virStoragePoolDefParseFile(path))) + if (!(def =3D virStoragePoolDefParseFile(path, 0))) return NULL; =20 if (!virFileMatchesNameSuffix(file, def->name, ".xml")) { @@ -1172,7 +1172,7 @@ virStoragePoolObjLoadState(virStoragePoolObjListPtr p= ools, } =20 ctxt->node =3D node; - if (!(def =3D virStoragePoolDefParseXML(ctxt))) + if (!(def =3D virStoragePoolDefParseXML(ctxt, 0))) goto error; =20 if (STRNEQ(name, def->name)) { diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index d78de83231..99d5dedd81 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -2635,7 +2635,7 @@ phypStoragePoolCreateXML(virConnectPtr conn, virStoragePoolPtr dup_sp =3D NULL; virStoragePoolPtr sp =3D NULL; =20 - if (!(def =3D virStoragePoolDefParseString(xml))) + if (!(def =3D virStoragePoolDefParseString(xml, 0))) goto err; =20 /* checking if this name already exists on this system */ diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 8070d159ea..491c4fab9b 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -699,7 +699,7 @@ storagePoolCreateXML(virConnectPtr conn, VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE, VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, NULL); =20 - if (!(newDef =3D virStoragePoolDefParseString(xml))) + if (!(newDef =3D virStoragePoolDefParseString(xml, 0))) goto cleanup; =20 if (virStoragePoolCreateXMLEnsureACL(conn, newDef) < 0) @@ -790,7 +790,7 @@ storagePoolDefineXML(virConnectPtr conn, =20 virCheckFlags(0, NULL); =20 - if (!(newDef =3D virStoragePoolDefParseString(xml))) + if (!(newDef =3D virStoragePoolDefParseString(xml, 0))) goto cleanup; =20 if (virXMLCheckIllegalChars("name", newDef->name, "\n") < 0) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index dfca95c981..1a42a4f74b 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1104,7 +1104,7 @@ testParseStorage(testDriverPtr privconn, if (!node) goto error; =20 - def =3D virStoragePoolDefParseNode(ctxt->doc, node); + def =3D virStoragePoolDefParseNode(ctxt->doc, node, 0); if (!def) goto error; =20 @@ -4519,7 +4519,7 @@ testStoragePoolCreateXML(virConnectPtr conn, virCheckFlags(0, NULL); =20 testDriverLock(privconn); - if (!(newDef =3D virStoragePoolDefParseString(xml))) + if (!(newDef =3D virStoragePoolDefParseString(xml, 0))) goto cleanup; =20 if (virStoragePoolObjIsDuplicate(privconn->pools, newDef, true) < 0) @@ -4589,7 +4589,7 @@ testStoragePoolDefineXML(virConnectPtr conn, virCheckFlags(0, NULL); =20 testDriverLock(privconn); - if (!(newDef =3D virStoragePoolDefParseString(xml))) + if (!(newDef =3D virStoragePoolDefParseString(xml, 0))) goto cleanup; =20 newDef->capacity =3D defaultPoolCap; diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheep= dogtest.c index cc7b163241..c9b80127b8 100644 --- a/tests/storagebackendsheepdogtest.c +++ b/tests/storagebackendsheepdogtest.c @@ -65,7 +65,7 @@ test_node_info_parser(const void *opaque) char *output =3D NULL; virStoragePoolDefPtr pool =3D NULL; =20 - if (!(pool =3D virStoragePoolDefParseFile(data->poolxml))) + if (!(pool =3D virStoragePoolDefParseFile(data->poolxml, 0))) goto cleanup; =20 if (VIR_STRDUP(output, test.output) < 0) @@ -100,7 +100,7 @@ test_vdi_list_parser(const void *opaque) virStoragePoolDefPtr pool =3D NULL; virStorageVolDefPtr vol =3D NULL; =20 - if (!(pool =3D virStoragePoolDefParseFile(data->poolxml))) + if (!(pool =3D virStoragePoolDefParseFile(data->poolxml, 0))) goto cleanup; =20 if (!(vol =3D virStorageVolDefParseFile(pool, data->volxml, 0))) diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index 974f0afe39..84f2bfb9ec 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -23,7 +23,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *o= utxml) int ret =3D -1; virStoragePoolDefPtr dev =3D NULL; =20 - if (!(dev =3D virStoragePoolDefParseFile(inxml))) + if (!(dev =3D virStoragePoolDefParseFile(inxml, 0))) goto fail; =20 if (!(actual =3D virStoragePoolDefFormat(dev))) diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index b795f83aee..aa55e4dbad 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -53,7 +53,7 @@ testCompareXMLToArgvFiles(bool shouldFail, virStoragePoolDefPtr inputpool =3D NULL; virStoragePoolObjPtr obj =3D NULL; =20 - if (!(def =3D virStoragePoolDefParseFile(poolxml))) + if (!(def =3D virStoragePoolDefParseFile(poolxml, 0))) goto cleanup; =20 if (!(obj =3D virStoragePoolObjNew())) { @@ -63,7 +63,7 @@ testCompareXMLToArgvFiles(bool shouldFail, virStoragePoolObjSetDef(obj, def); =20 if (inputpoolxml) { - if (!(inputpool =3D virStoragePoolDefParseFile(inputpoolxml))) + if (!(inputpool =3D virStoragePoolDefParseFile(inputpoolxml, 0))) goto cleanup; } =20 diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index 7bac4974ae..0ff25451bc 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -25,7 +25,7 @@ testCompareXMLToXMLFiles(const char *poolxml, const char = *inxml, virStoragePoolDefPtr pool =3D NULL; virStorageVolDefPtr dev =3D NULL; =20 - if (!(pool =3D virStoragePoolDefParseFile(poolxml))) + if (!(pool =3D virStoragePoolDefParseFile(poolxml, 0))) goto fail; =20 if (!(dev =3D virStorageVolDefParseFile(pool, inxml, flags))) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 07:45: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 1532976467950766.608675558326; Mon, 30 Jul 2018 11:47:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84724C057FA3; Mon, 30 Jul 2018 18:47:07 +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 4198730C06A5; Mon, 30 Jul 2018 18:47:06 +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 AFBAA4A460; Mon, 30 Jul 2018 18:47:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UIl1sq000469 for ; Mon, 30 Jul 2018 14:47:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id ACE3DD0CEF; Mon, 30 Jul 2018 18:47:01 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-84.phx2.redhat.com [10.3.116.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D45DD09A4 for ; Mon, 30 Jul 2018 18:46:57 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 14:46:39 -0400 Message-Id: <20180730184648.5059-3-jferlan@redhat.com> In-Reply-To: <20180730184648.5059-1-jferlan@redhat.com> References: <20180730184648.5059-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/11] conf: Disallow new storage pools to use all white space as name 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 30 Jul 2018 18:47:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1107420 Add a new define/create flag VIR_STORAGE_POOL_DEF_PARSE_VALIDATE_NAME to disallow new storage pools to be defined/created using a name comprised entirely of spaces. Alter the storagepoolxml2xmltest to add a parse failure scenario and a test in order to prove the failure occurs. Signed-off-by: John Ferlan --- src/conf/storage_conf.c | 9 +++- src/conf/storage_conf.h | 7 +++ src/storage/storage_driver.c | 6 ++- .../pool-dir-whitespace-name.xml | 18 ++++++++ tests/storagepoolxml2xmltest.c | 45 +++++++++++++++---- 5 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 tests/storagepoolxml2xmlin/pool-dir-whitespace-name.xml diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index e5d35cd254..e8bbe4ea54 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -681,7 +681,7 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt, char *uuid =3D NULL; char *target_path =3D NULL; =20 - virCheckFlags(0, NULL); + virCheckFlags(VIR_STORAGE_POOL_DEF_PARSE_VALIDATE_NAME, NULL); =20 if (VIR_ALLOC(ret) < 0) return NULL; @@ -729,6 +729,13 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt, goto error; } =20 + if ((flags & VIR_STORAGE_POOL_DEF_PARSE_VALIDATE_NAME) && + virStringIsEmpty(ret->name)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("name must contain at least one non blank charact= er")); + goto error; + } + uuid =3D virXPathString("string(./uuid)", ctxt); if (uuid =3D=3D NULL) { if (virUUIDGenerate(ret->uuid) < 0) { diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index d6886ad6ca..31851643e9 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -235,6 +235,13 @@ struct _virStoragePoolSourceList { virStoragePoolSourcePtr sources; }; =20 +typedef enum { + /* Perform extra name validation on new storage pool names which + * will cause failure to parse the XML. Initially just that a + * name cannot be all white space. */ + VIR_STORAGE_POOL_DEF_PARSE_VALIDATE_NAME =3D 1 << 0, +} virStoragePoolDefParseFlags; + virStoragePoolDefPtr virStoragePoolDefParseXML(xmlXPathContextPtr ctxt, unsigned int flags); diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 491c4fab9b..8d7a7b399c 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -690,6 +690,7 @@ storagePoolCreateXML(virConnectPtr conn, virStorageBackendPtr backend; virObjectEventPtr event =3D NULL; char *stateFile =3D NULL; + unsigned int parse_flags =3D VIR_STORAGE_POOL_DEF_PARSE_VALIDATE_NAME; unsigned int build_flags =3D 0; =20 virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD | @@ -699,7 +700,7 @@ storagePoolCreateXML(virConnectPtr conn, VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE, VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, NULL); =20 - if (!(newDef =3D virStoragePoolDefParseString(xml, 0))) + if (!(newDef =3D virStoragePoolDefParseString(xml, parse_flags))) goto cleanup; =20 if (virStoragePoolCreateXMLEnsureACL(conn, newDef) < 0) @@ -787,10 +788,11 @@ storagePoolDefineXML(virConnectPtr conn, virStoragePoolDefPtr def; virStoragePoolPtr pool =3D NULL; virObjectEventPtr event =3D NULL; + unsigned int parse_flags =3D VIR_STORAGE_POOL_DEF_PARSE_VALIDATE_NAME; =20 virCheckFlags(0, NULL); =20 - if (!(newDef =3D virStoragePoolDefParseString(xml, 0))) + if (!(newDef =3D virStoragePoolDefParseString(xml, parse_flags))) goto cleanup; =20 if (virXMLCheckIllegalChars("name", newDef->name, "\n") < 0) diff --git a/tests/storagepoolxml2xmlin/pool-dir-whitespace-name.xml b/test= s/storagepoolxml2xmlin/pool-dir-whitespace-name.xml new file mode 100644 index 0000000000..024505df03 --- /dev/null +++ b/tests/storagepoolxml2xmlin/pool-dir-whitespace-name.xml @@ -0,0 +1,18 @@ + + + 70a7eb15-6c34-ee9c-bf57-69e8e5ff3fb2 + 0 + 0 + 0 + + + + ///var/////lib/libvirt/images// + + 0700 + -1 + -1 + + + + diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index 84f2bfb9ec..7893e79da8 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -17,14 +17,24 @@ #define VIR_FROM_THIS VIR_FROM_NONE =20 static int -testCompareXMLToXMLFiles(const char *inxml, const char *outxml) +testCompareXMLToXMLFiles(const char *inxml, + const char *outxml, + bool expect_parse_fail) { char *actual =3D NULL; int ret =3D -1; virStoragePoolDefPtr dev =3D NULL; - - if (!(dev =3D virStoragePoolDefParseFile(inxml, 0))) + unsigned int parse_flags =3D VIR_STORAGE_POOL_DEF_PARSE_VALIDATE_NAME; + + if (!(dev =3D virStoragePoolDefParseFile(inxml, parse_flags))) { + if (expect_parse_fail) { + VIR_TEST_DEBUG("Got expected parse failure msg=3D'%s'", + virGetLastErrorMessage()); + virResetLastError(); + ret =3D 0; + } goto fail; + } =20 if (!(actual =3D virStoragePoolDefFormat(dev))) goto fail; @@ -40,21 +50,28 @@ testCompareXMLToXMLFiles(const char *inxml, const char = *outxml) return ret; } =20 + +typedef struct test_params { + const char *name; + bool expect_parse_fail; +} test_params; + static int testCompareXMLToXMLHelper(const void *data) { int result =3D -1; char *inxml =3D NULL; char *outxml =3D NULL; + const test_params *tp =3D data; =20 if (virAsprintf(&inxml, "%s/storagepoolxml2xmlin/%s.xml", - abs_srcdir, (const char*)data) < 0 || + abs_srcdir, tp->name) < 0 || virAsprintf(&outxml, "%s/storagepoolxml2xmlout/%s.xml", - abs_srcdir, (const char*)data) < 0) { + abs_srcdir, tp->name) < 0) { goto cleanup; } =20 - result =3D testCompareXMLToXMLFiles(inxml, outxml); + result =3D testCompareXMLToXMLFiles(inxml, outxml, tp->expect_parse_fa= il); =20 cleanup: VIR_FREE(inxml); @@ -68,13 +85,23 @@ mymain(void) { int ret =3D 0; =20 +#define DO_TEST_FULL(name, expect_parse_fail) \ + do { \ + test_params tp =3D {name, expect_parse_fail}; \ + if (virTestRun("Storage Pool XML-2-XML " name, \ + testCompareXMLToXMLHelper, &tp) < 0) \ + ret =3D -1; \ + } while (0) + #define DO_TEST(name) \ - if (virTestRun("Storage Pool XML-2-XML " name, \ - testCompareXMLToXMLHelper, (name)) < 0) \ - ret =3D -1 + DO_TEST_FULL(name, false); + +#define DO_TEST_PARSE_FAIL(name) \ + DO_TEST_FULL(name, true); =20 DO_TEST("pool-dir"); DO_TEST("pool-dir-naming"); + DO_TEST_PARSE_FAIL("pool-dir-whitespace-name"); DO_TEST("pool-fs"); DO_TEST("pool-logical"); DO_TEST("pool-logical-nopath"); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 07:45: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 153297643021895.84436371435095; Mon, 30 Jul 2018 11:47:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A4C5308FBA5; Mon, 30 Jul 2018 18:47:07 +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 5962718E24; Mon, 30 Jul 2018 18:47:06 +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 0AC8C18037F0; Mon, 30 Jul 2018 18:47:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UIl2JG000474 for ; Mon, 30 Jul 2018 14:47:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 25640D0F8F; Mon, 30 Jul 2018 18:47:02 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-84.phx2.redhat.com [10.3.116.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB064D09A4 for ; Mon, 30 Jul 2018 18:47:01 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 14:46:40 -0400 Message-Id: <20180730184648.5059-4-jferlan@redhat.com> In-Reply-To: <20180730184648.5059-1-jferlan@redhat.com> References: <20180730184648.5059-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/11] conf: Add @flags to Network Def processing 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 30 Jul 2018 18:47:08 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a @flags argument when parsing the network definition via the virNetworkDefParse{XML|Node|String|File} API's as this will allow us to in the future make parsing decisions based on the @flags. Signed-off-by: John Ferlan --- src/conf/domain_conf.c | 2 +- src/conf/network_conf.c | 27 +++++++++++++++++---------- src/conf/network_conf.h | 12 ++++++++---- src/conf/virnetworkobj.c | 4 ++-- src/esx/esx_network_driver.c | 2 +- src/network/bridge_driver.c | 4 ++-- src/qemu/qemu_process.c | 2 +- src/test/test_driver.c | 6 +++--- src/vbox/vbox_network.c | 2 +- tests/networkxml2conftest.c | 2 +- tests/networkxml2firewalltest.c | 2 +- tests/networkxml2xmltest.c | 2 +- tests/networkxml2xmlupdatetest.c | 2 +- 13 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 42b55f01d4..705575fe92 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30004,7 +30004,7 @@ virDomainNetResolveActualType(virDomainNetDefPtr if= ace) if (!(xml =3D virNetworkGetXMLDesc(net, 0))) goto cleanup; =20 - if (!(def =3D virNetworkDefParseString(xml))) + if (!(def =3D virNetworkDefParseString(xml, 0))) goto cleanup; =20 switch ((virNetworkForwardType) def->forward.type) { diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index c08456ba96..34d132e506 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -259,7 +259,7 @@ virNetworkDefCopy(virNetworkDefPtr def, unsigned int fl= ags) /* deep copy with a format/parse cycle */ if (!(xml =3D virNetworkDefFormat(def, flags))) goto cleanup; - newDef =3D virNetworkDefParseString(xml); + newDef =3D virNetworkDefParseString(xml, 0); cleanup: VIR_FREE(xml); return newDef; @@ -1584,7 +1584,8 @@ virNetworkForwardDefParseXML(const char *networkName, =20 =20 virNetworkDefPtr -virNetworkDefParseXML(xmlXPathContextPtr ctxt) +virNetworkDefParseXML(xmlXPathContextPtr ctxt, + unsigned int flags) { virNetworkDefPtr def; char *tmp =3D NULL; @@ -1603,6 +1604,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) xmlNodePtr vlanNode; xmlNodePtr metadataNode =3D NULL; =20 + virCheckFlags(0, NULL); + if (VIR_ALLOC(def) < 0) return NULL; =20 @@ -2016,14 +2019,15 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) =20 static virNetworkDefPtr virNetworkDefParse(const char *xmlStr, - const char *filename) + const char *filename, + unsigned int flags) { xmlDocPtr xml; virNetworkDefPtr def =3D NULL; int keepBlanksDefault =3D xmlKeepBlanksDefault(0); =20 if ((xml =3D virXMLParse(filename, xmlStr, _("(network_definition)")))= ) { - def =3D virNetworkDefParseNode(xml, xmlDocGetRootElement(xml)); + def =3D virNetworkDefParseNode(xml, xmlDocGetRootElement(xml), fla= gs); xmlFreeDoc(xml); } =20 @@ -2033,22 +2037,25 @@ virNetworkDefParse(const char *xmlStr, =20 =20 virNetworkDefPtr -virNetworkDefParseString(const char *xmlStr) +virNetworkDefParseString(const char *xmlStr, + unsigned int flags) { - return virNetworkDefParse(xmlStr, NULL); + return virNetworkDefParse(xmlStr, NULL, flags); } =20 =20 virNetworkDefPtr -virNetworkDefParseFile(const char *filename) +virNetworkDefParseFile(const char *filename, + unsigned int flags) { - return virNetworkDefParse(NULL, filename); + return virNetworkDefParse(NULL, filename, flags); } =20 =20 virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml, - xmlNodePtr root) + xmlNodePtr root, + unsigned int flags) { xmlXPathContextPtr ctxt =3D NULL; virNetworkDefPtr def =3D NULL; @@ -2068,7 +2075,7 @@ virNetworkDefParseNode(xmlDocPtr xml, } =20 ctxt->node =3D root; - def =3D virNetworkDefParseXML(ctxt); + def =3D virNetworkDefParseXML(ctxt, flags); =20 cleanup: xmlXPathFreeContext(ctxt); diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 54c8ed1c4c..6373b783c6 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -294,17 +294,21 @@ virNetworkDefPtr virNetworkDefCopy(virNetworkDefPtr def, unsigned int flags); =20 virNetworkDefPtr -virNetworkDefParseXML(xmlXPathContextPtr ctxt); +virNetworkDefParseXML(xmlXPathContextPtr ctxt, + unsigned int flags); =20 virNetworkDefPtr -virNetworkDefParseString(const char *xmlStr); +virNetworkDefParseString(const char *xmlStr, + unsigned int flags); =20 virNetworkDefPtr -virNetworkDefParseFile(const char *filename); +virNetworkDefParseFile(const char *filename, + unsigned int flags); =20 virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml, - xmlNodePtr root); + xmlNodePtr root, + unsigned int flags); =20 char * virNetworkDefFormat(const virNetworkDef *def, diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index b13e5a7b03..d7357007d3 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -885,7 +885,7 @@ virNetworkLoadState(virNetworkObjListPtr nets, =20 /* parse the definition first */ ctxt->node =3D node; - if (!(def =3D virNetworkDefParseXML(ctxt))) + if (!(def =3D virNetworkDefParseXML(ctxt, 0))) goto error; =20 if (STRNEQ(name, def->name)) { @@ -998,7 +998,7 @@ virNetworkLoadConfig(virNetworkObjListPtr nets, if ((autostart =3D virFileLinkPointsTo(autostartLink, configFile)) < 0) goto error; =20 - if (!(def =3D virNetworkDefParseFile(configFile))) + if (!(def =3D virNetworkDefParseFile(configFile, 0))) goto error; =20 if (STRNEQ(name, def->name)) { diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index 31bceb7bff..5e2b2b50f7 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -298,7 +298,7 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml) return NULL; =20 /* Parse network XML */ - def =3D virNetworkDefParseString(xml); + def =3D virNetworkDefParseString(xml, 0); =20 if (!def) return NULL; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index f92cc61e47..eef0d83c10 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -3609,7 +3609,7 @@ networkCreateXML(virConnectPtr conn, virNetworkPtr net =3D NULL; virObjectEventPtr event =3D NULL; =20 - if (!(newDef =3D virNetworkDefParseString(xml))) + if (!(newDef =3D virNetworkDefParseString(xml, 0))) goto cleanup; =20 if (virNetworkCreateXMLEnsureACL(conn, newDef) < 0) @@ -3661,7 +3661,7 @@ networkDefineXML(virConnectPtr conn, virNetworkPtr net =3D NULL; virObjectEventPtr event =3D NULL; =20 - if (!(def =3D virNetworkDefParseString(xml))) + if (!(def =3D virNetworkDefParseString(xml, 0))) goto cleanup; =20 if (virNetworkDefineXMLEnsureACL(conn, def) < 0) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c4e33723d1..ccf6c662c9 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4541,7 +4541,7 @@ qemuProcessGetNetworkAddress(const char *netname, if (!xml) goto cleanup; =20 - netdef =3D virNetworkDefParseString(xml); + netdef =3D virNetworkDefParseString(xml, 0); if (!netdef) goto cleanup; =20 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 1a42a4f74b..9826ac3fee 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -966,7 +966,7 @@ testParseNetworks(testDriverPtr privconn, if (!node) goto error; =20 - def =3D virNetworkDefParseNode(ctxt->doc, node); + def =3D virNetworkDefParseNode(ctxt->doc, node, 0); if (!def) goto error; =20 @@ -3462,7 +3462,7 @@ testNetworkCreateXML(virConnectPtr conn, const char *= xml) virNetworkPtr net =3D NULL; virObjectEventPtr event =3D NULL; =20 - if ((newDef =3D virNetworkDefParseString(xml)) =3D=3D NULL) + if ((newDef =3D virNetworkDefParseString(xml, 0)) =3D=3D NULL) goto cleanup; =20 if (!(obj =3D virNetworkObjAssignDef(privconn->networks, newDef, @@ -3498,7 +3498,7 @@ testNetworkDefineXML(virConnectPtr conn, virNetworkPtr net =3D NULL; virObjectEventPtr event =3D NULL; =20 - if ((newDef =3D virNetworkDefParseString(xml)) =3D=3D NULL) + if ((newDef =3D virNetworkDefParseString(xml, 0)) =3D=3D NULL) goto cleanup; =20 if (!(obj =3D virNetworkObjAssignDef(privconn->networks, newDef, 0))) diff --git a/src/vbox/vbox_network.c b/src/vbox/vbox_network.c index 50a7a56303..eb47abaf00 100644 --- a/src/vbox/vbox_network.c +++ b/src/vbox/vbox_network.c @@ -375,7 +375,7 @@ vboxNetworkDefineCreateXML(virConnectPtr conn, const ch= ar *xml, bool start) PRUnichar *networkNameUtf16 =3D NULL; char *networkNameUtf8 =3D NULL; IHostNetworkInterface *networkInterface =3D NULL; - virNetworkDefPtr def =3D virNetworkDefParseString(xml); + virNetworkDefPtr def =3D virNetworkDefParseString(xml, 0); virNetworkIPDefPtr ipdef =3D NULL; unsigned char uuid[VIR_UUID_BUFLEN]; vboxIID vboxnetiid; diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index 8e7751e36b..569763f0e6 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -29,7 +29,7 @@ testCompareXMLToConfFiles(const char *inxml, const char *= outconf, dnsmasqCapsPtr char *pidfile =3D NULL; dnsmasqContext *dctx =3D NULL; =20 - if (!(def =3D virNetworkDefParseFile(inxml))) + if (!(def =3D virNetworkDefParseFile(inxml, 0))) goto fail; =20 if (!(obj =3D virNetworkObjNew())) diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltes= t.c index 242b645767..49f0300a29 100644 --- a/tests/networkxml2firewalltest.c +++ b/tests/networkxml2firewalltest.c @@ -55,7 +55,7 @@ static int testCompareXMLToArgvFiles(const char *xml, =20 virCommandSetDryRun(&buf, NULL, NULL); =20 - if (!(def =3D virNetworkDefParseFile(xml))) + if (!(def =3D virNetworkDefParseFile(xml, 0))) goto cleanup; =20 if (networkAddFirewallRules(def) < 0) diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index eb7db766fa..7828995df1 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -33,7 +33,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *o= utxml, testCompareNetXML2XMLResult result =3D TEST_COMPARE_NET_XML2XML_RESULT= _SUCCESS; virNetworkDefPtr dev =3D NULL; =20 - if (!(dev =3D virNetworkDefParseFile(inxml))) { + if (!(dev =3D virNetworkDefParseFile(inxml, 0))) { result =3D TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE; goto cleanup; } diff --git a/tests/networkxml2xmlupdatetest.c b/tests/networkxml2xmlupdatet= est.c index b4b44ceff3..dfb21c0064 100644 --- a/tests/networkxml2xmlupdatetest.c +++ b/tests/networkxml2xmlupdatetest.c @@ -30,7 +30,7 @@ testCompareXMLToXMLFiles(const char *netxml, const char *= updatexml, if (virTestLoadFile(updatexml, &updateXmlData) < 0) goto error; =20 - if (!(def =3D virNetworkDefParseFile(netxml))) + if (!(def =3D virNetworkDefParseFile(netxml, 0))) goto fail; =20 if (virNetworkDefUpdateSection(def, command, section, parentIndex, --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 07:45: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 1532976468088938.8121984171835; Mon, 30 Jul 2018 11:47:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A520308FBA1; Mon, 30 Jul 2018 18:47:38 +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 E407EBA94; Mon, 30 Jul 2018 18:47:37 +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 82F7518037F2; Mon, 30 Jul 2018 18:47:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UIlEMf000509 for ; Mon, 30 Jul 2018 14:47:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4DDDFD09A4; Mon, 30 Jul 2018 18:47:14 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-84.phx2.redhat.com [10.3.116.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25FE0D0FC2 for ; Mon, 30 Jul 2018 18:47:02 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 14:46:41 -0400 Message-Id: <20180730184648.5059-5-jferlan@redhat.com> In-Reply-To: <20180730184648.5059-1-jferlan@redhat.com> References: <20180730184648.5059-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/11] conf: Disallow new networks to use all white space as name 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 30 Jul 2018 18:47:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1107420 Add a new define/create flag VIR_NETWORK_DEF_PARSE_VALIDATE_NAME to disallow new networks to be defined/created using a name comprised entirely of spaces. Alter the networkxml2xmltest to add a test in order to prove the failure occurs. Signed-off-by: John Ferlan --- src/conf/network_conf.c | 9 ++++++++- src/conf/network_conf.h | 7 +++++++ src/network/bridge_driver.c | 6 ++++-- tests/networkxml2xmlin/network-whitespace-name.xml | 6 ++++++ tests/networkxml2xmltest.c | 4 +++- 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 tests/networkxml2xmlin/network-whitespace-name.xml diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 34d132e506..2139f61c82 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1604,7 +1604,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt, xmlNodePtr vlanNode; xmlNodePtr metadataNode =3D NULL; =20 - virCheckFlags(0, NULL); + virCheckFlags(VIR_NETWORK_DEF_PARSE_VALIDATE_NAME, NULL); =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -1619,6 +1619,13 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt, if (virXMLCheckIllegalChars("name", def->name, "/") < 0) goto error; =20 + if ((flags & VIR_NETWORK_DEF_PARSE_VALIDATE_NAME) && + virStringIsEmpty(def->name)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("name must contain at least one non blank charact= er")); + goto error; + } + /* Extract network uuid */ tmp =3D virXPathString("string(./uuid[1])", ctxt); if (!tmp) { diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 6373b783c6..53c187b075 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -293,6 +293,13 @@ enum { virNetworkDefPtr virNetworkDefCopy(virNetworkDefPtr def, unsigned int flags); =20 +typedef enum { + /* Perform extra name validation on new network names which + * will cause failure to parse the XML. Initially just that a + * name cannot be all white space. */ + VIR_NETWORK_DEF_PARSE_VALIDATE_NAME =3D 1 << 0, +} virNetworkDefParseFlags; + virNetworkDefPtr virNetworkDefParseXML(xmlXPathContextPtr ctxt, unsigned int flags); diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index eef0d83c10..33e28c3666 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -3608,8 +3608,9 @@ networkCreateXML(virConnectPtr conn, virNetworkDefPtr def; virNetworkPtr net =3D NULL; virObjectEventPtr event =3D NULL; + unsigned int parse_flags =3D VIR_NETWORK_DEF_PARSE_VALIDATE_NAME; =20 - if (!(newDef =3D virNetworkDefParseString(xml, 0))) + if (!(newDef =3D virNetworkDefParseString(xml, parse_flags))) goto cleanup; =20 if (virNetworkCreateXMLEnsureACL(conn, newDef) < 0) @@ -3660,8 +3661,9 @@ networkDefineXML(virConnectPtr conn, virNetworkObjPtr obj =3D NULL; virNetworkPtr net =3D NULL; virObjectEventPtr event =3D NULL; + unsigned int parse_flags =3D VIR_NETWORK_DEF_PARSE_VALIDATE_NAME; =20 - if (!(def =3D virNetworkDefParseString(xml, 0))) + if (!(def =3D virNetworkDefParseString(xml, parse_flags))) goto cleanup; =20 if (virNetworkDefineXMLEnsureACL(conn, def) < 0) diff --git a/tests/networkxml2xmlin/network-whitespace-name.xml b/tests/net= workxml2xmlin/network-whitespace-name.xml new file mode 100644 index 0000000000..31d54985b4 --- /dev/null +++ b/tests/networkxml2xmlin/network-whitespace-name.xml @@ -0,0 +1,6 @@ + + + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index 7828995df1..42063f9904 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -32,8 +32,9 @@ testCompareXMLToXMLFiles(const char *inxml, const char *o= utxml, int ret; testCompareNetXML2XMLResult result =3D TEST_COMPARE_NET_XML2XML_RESULT= _SUCCESS; virNetworkDefPtr dev =3D NULL; + unsigned int parse_flags =3D VIR_NETWORK_DEF_PARSE_VALIDATE_NAME; =20 - if (!(dev =3D virNetworkDefParseFile(inxml, 0))) { + if (!(dev =3D virNetworkDefParseFile(inxml, parse_flags))) { result =3D TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE; goto cleanup; } @@ -160,6 +161,7 @@ mymain(void) DO_TEST_PARSE_ERROR("passthrough-duplicate"); DO_TEST("metadata"); DO_TEST("set-mtu"); + DO_TEST_PARSE_ERROR("network-whitespace-name"); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 07:45: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 1532976468109403.55731261650806; Mon, 30 Jul 2018 11:47:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F6B830832D7; Mon, 30 Jul 2018 18:47:40 +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 E0FA92010CCD; Mon, 30 Jul 2018 18:47:39 +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 8F10E4A46E; Mon, 30 Jul 2018 18:47:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UIlPJw000532 for ; Mon, 30 Jul 2018 14:47:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id DC6F1D09A4; Mon, 30 Jul 2018 18:47:25 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-84.phx2.redhat.com [10.3.116.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id A49CCC6A0E for ; Mon, 30 Jul 2018 18:47:06 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 14:46:42 -0400 Message-Id: <20180730184648.5059-6-jferlan@redhat.com> In-Reply-To: <20180730184648.5059-1-jferlan@redhat.com> References: <20180730184648.5059-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/11] conf: Disallow new qemu, lxc domains to use all white space as name 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 30 Jul 2018 18:47:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1107420 Add a new define/create flag VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME to disallow new domains to be defined/created using a name comprised entirely of spaces. Alter the qemuxml2argvtest to add a test in order to prove the failure occurs. Signed-off-by: John Ferlan --- src/conf/domain_conf.c | 7 ++++++ src/conf/domain_conf.h | 4 +++ src/lxc/lxc_driver.c | 6 +++-- src/qemu/qemu_driver.c | 6 +++-- tests/qemuxml2argvdata/name-whitespace.xml | 29 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 5 +++- 6 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 tests/qemuxml2argvdata/name-whitespace.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 705575fe92..6620ff89af 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19278,6 +19278,13 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } =20 + if ((flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME) && + virStringIsEmpty(def->name)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("name must contain at least one non blank charact= er")); + goto error; + } + /* Extract domain uuid. If both uuid and sysinfo/system/entry/uuid * exist, they must match; and if only the latter exists, it can * also serve as the uuid. */ diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c1dfa37fdf..7eb020d6d7 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2996,6 +2996,10 @@ typedef enum { * post parse callbacks before starting. Failure of the post parse cal= lback * is recorded as def->postParseFail */ VIR_DOMAIN_DEF_PARSE_ALLOW_POST_PARSE_FAIL =3D 1 << 12, + /* Perform extra name validation on new domain names which + * will cause failure to parse the XML. Initially just that a + * name cannot be all white space. */ + VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME =3D 1 << 13, } virDomainDefParseFlags; =20 typedef enum { diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 8867645cdc..5d1082292d 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -418,7 +418,8 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char = *xml, unsigned int flags) virDomainDefPtr oldDef =3D NULL; virLXCDriverConfigPtr cfg =3D virLXCDriverGetConfig(driver); virCapsPtr caps =3D NULL; - unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE | + VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME; =20 virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL); =20 @@ -1163,7 +1164,8 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, virObjectEventPtr event =3D NULL; virLXCDriverConfigPtr cfg =3D virLXCDriverGetConfig(driver); virCapsPtr caps =3D NULL; - unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE | + VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME; =20 virCheckFlags(VIR_DOMAIN_START_AUTODESTROY | VIR_DOMAIN_START_VALIDATE, NULL); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index fb0d4a8c7a..37f10d286e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1710,7 +1710,8 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr= conn, unsigned int start_flags =3D VIR_QEMU_PROCESS_START_COLD; virCapsPtr caps =3D NULL; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE | - VIR_DOMAIN_DEF_PARSE_ABI_UPDATE; + VIR_DOMAIN_DEF_PARSE_ABI_UPDATE | + VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME; =20 virCheckFlags(VIR_DOMAIN_START_PAUSED | VIR_DOMAIN_START_AUTODESTROY | @@ -7381,7 +7382,8 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, virQEMUDriverConfigPtr cfg; virCapsPtr caps =3D NULL; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE | - VIR_DOMAIN_DEF_PARSE_ABI_UPDATE; + VIR_DOMAIN_DEF_PARSE_ABI_UPDATE | + VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME; =20 virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL); =20 diff --git a/tests/qemuxml2argvdata/name-whitespace.xml b/tests/qemuxml2arg= vdata/name-whitespace.xml new file mode 100644 index 0000000000..e143c7c770 --- /dev/null +++ b/tests/qemuxml2argvdata/name-whitespace.xml @@ -0,0 +1,29 @@ + + + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + +
+ + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 84117a3e63..e92bcd0df6 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -494,7 +494,8 @@ testCompareXMLToArgv(const void *data) if (!(vm =3D virDomainObjNew(driver.xmlopt))) goto cleanup; =20 - parseFlags |=3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + parseFlags |=3D VIR_DOMAIN_DEF_PARSE_INACTIVE | + VIR_DOMAIN_DEF_PARSE_VALIDATE_NAME; if (!(vm->def =3D virDomainDefParseFile(xml, driver.caps, driver.xmlop= t, NULL, parseFlags))) { if (flags & FLAG_EXPECT_PARSE_ERROR) @@ -822,6 +823,8 @@ mymain(void) DO_TEST_PARSE_ERROR("minimal-no-memory", NONE); DO_TEST("minimal-msg-timestamp", QEMU_CAPS_MSG_TIMESTAMP); =20 + DO_TEST_PARSE_ERROR("name-whitespace", NONE); + DO_TEST_CAPS_LATEST("genid"); DO_TEST_CAPS_LATEST("genid-auto"); =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 07:45: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 1532976468907264.03797352012293; Mon, 30 Jul 2018 11:47:48 -0700 (PDT) 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 46063461CF; Mon, 30 Jul 2018 18:47:43 +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 0C7527650C; Mon, 30 Jul 2018 18:47:43 +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 A7F243FCC1; Mon, 30 Jul 2018 18:47:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UIlORB000523 for ; Mon, 30 Jul 2018 14:47:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 12171D033A; Mon, 30 Jul 2018 18:47:24 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-84.phx2.redhat.com [10.3.116.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 908E6C8742 for ; Mon, 30 Jul 2018 18:47:17 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 14:46:43 -0400 Message-Id: <20180730184648.5059-7-jferlan@redhat.com> In-Reply-To: <20180730184648.5059-1-jferlan@redhat.com> References: <20180730184648.5059-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/11] conf: Split and rename secretXMLParseNode 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.29]); Mon, 30 Jul 2018 18:47:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Split/rename secretXMLParseNode to virSecretDefParseNode and virSecretDefParseXML in order to follow other drivers usage and naming of the same functionality. Signed-off-by: John Ferlan --- src/conf/secret_conf.c | 56 ++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index 7a2e4b28aa..faf44bccce 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -121,29 +121,14 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt, return 0; } =20 + static virSecretDefPtr -secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) +virSecretDefParseXML(xmlXPathContextPtr ctxt) { - xmlXPathContextPtr ctxt =3D NULL; virSecretDefPtr def =3D NULL, ret =3D NULL; char *prop =3D NULL; char *uuidstr =3D NULL; =20 - if (!virXMLNodeNameEqual(root, "secret")) { - virReportError(VIR_ERR_XML_ERROR, - _("unexpected root element <%s>, " - "expecting "), - root->name); - goto cleanup; - } - - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); - goto cleanup; - } - ctxt->node =3D root; - if (VIR_ALLOC(def) < 0) goto cleanup; =20 @@ -195,17 +180,46 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) if (virXPathNode("./usage", ctxt) !=3D NULL && virSecretDefParseUsage(ctxt, def) < 0) goto cleanup; - ret =3D def; - def =3D NULL; + VIR_STEAL_PTR(ret, def); =20 cleanup: VIR_FREE(prop); VIR_FREE(uuidstr); virSecretDefFree(def); - xmlXPathFreeContext(ctxt); return ret; } =20 + +static virSecretDefPtr +virSecretDefParseNode(xmlDocPtr xml, + xmlNodePtr root) +{ + xmlXPathContextPtr ctxt =3D NULL; + virSecretDefPtr def =3D NULL; + + if (!virXMLNodeNameEqual(root, "secret")) { + virReportError(VIR_ERR_XML_ERROR, + _("unexpected root element <%s>, " + "expecting "), + root->name); + goto cleanup; + } + + ctxt =3D xmlXPathNewContext(xml); + if (ctxt =3D=3D NULL) { + virReportOOMError(); + goto cleanup; + } + ctxt->node =3D root; + + def =3D virSecretDefParseXML(ctxt); + + cleanup: + xmlXPathFreeContext(ctxt); + return def; +} + + static virSecretDefPtr virSecretDefParse(const char *xmlStr, const char *filename) @@ -214,7 +228,7 @@ virSecretDefParse(const char *xmlStr, virSecretDefPtr ret =3D NULL; =20 if ((xml =3D virXMLParse(filename, xmlStr, _("(definition_of_secret)")= ))) { - ret =3D secretXMLParseNode(xml, xmlDocGetRootElement(xml)); + ret =3D virSecretDefParseNode(xml, xmlDocGetRootElement(xml)); xmlFreeDoc(xml); } =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 07:45: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 1532976459955338.26938692392014; Mon, 30 Jul 2018 11:47:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DD4981DFF; Mon, 30 Jul 2018 18:47:36 +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 DE8A2BA92; Mon, 30 Jul 2018 18:47:35 +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 7A6514A469; Mon, 30 Jul 2018 18:47:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UIlXHM000554 for ; Mon, 30 Jul 2018 14:47:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id C3515D09BD; Mon, 30 Jul 2018 18:47:33 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-84.phx2.redhat.com [10.3.116.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FC19C6A0E for ; Mon, 30 Jul 2018 18:47:24 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 14:46:44 -0400 Message-Id: <20180730184648.5059-8-jferlan@redhat.com> In-Reply-To: <20180730184648.5059-1-jferlan@redhat.com> References: <20180730184648.5059-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/11] conf: Add @flags to Secret Def processing 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 30 Jul 2018 18:47:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a @flags argument when parsing the secret definition via the virSecretDefParse{XML|Node|String|File} API's as this will allow us to in the future make parsing decisions based on the @flags. Signed-off-by: John Ferlan --- src/conf/secret_conf.c | 25 ++++++++++++++++--------- src/conf/secret_conf.h | 9 +++++++-- src/conf/virsecretobj.c | 2 +- src/secret/secret_driver.c | 2 +- tests/secretxml2xmltest.c | 2 +- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index faf44bccce..d98a4f2442 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -123,12 +123,15 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt, =20 =20 static virSecretDefPtr -virSecretDefParseXML(xmlXPathContextPtr ctxt) +virSecretDefParseXML(xmlXPathContextPtr ctxt, + unsigned int flags) { virSecretDefPtr def =3D NULL, ret =3D NULL; char *prop =3D NULL; char *uuidstr =3D NULL; =20 + virCheckFlags(0, NULL); + if (VIR_ALLOC(def) < 0) goto cleanup; =20 @@ -192,7 +195,8 @@ virSecretDefParseXML(xmlXPathContextPtr ctxt) =20 static virSecretDefPtr virSecretDefParseNode(xmlDocPtr xml, - xmlNodePtr root) + xmlNodePtr root, + unsigned int flags) { xmlXPathContextPtr ctxt =3D NULL; virSecretDefPtr def =3D NULL; @@ -212,7 +216,7 @@ virSecretDefParseNode(xmlDocPtr xml, } ctxt->node =3D root; =20 - def =3D virSecretDefParseXML(ctxt); + def =3D virSecretDefParseXML(ctxt, flags); =20 cleanup: xmlXPathFreeContext(ctxt); @@ -222,13 +226,14 @@ virSecretDefParseNode(xmlDocPtr xml, =20 static virSecretDefPtr virSecretDefParse(const char *xmlStr, - const char *filename) + const char *filename, + unsigned int flags) { xmlDocPtr xml; virSecretDefPtr ret =3D NULL; =20 if ((xml =3D virXMLParse(filename, xmlStr, _("(definition_of_secret)")= ))) { - ret =3D virSecretDefParseNode(xml, xmlDocGetRootElement(xml)); + ret =3D virSecretDefParseNode(xml, xmlDocGetRootElement(xml), flag= s); xmlFreeDoc(xml); } =20 @@ -236,15 +241,17 @@ virSecretDefParse(const char *xmlStr, } =20 virSecretDefPtr -virSecretDefParseString(const char *xmlStr) +virSecretDefParseString(const char *xmlStr, + unsigned int flags) { - return virSecretDefParse(xmlStr, NULL); + return virSecretDefParse(xmlStr, NULL, flags); } =20 virSecretDefPtr -virSecretDefParseFile(const char *filename) +virSecretDefParseFile(const char *filename, + unsigned int flags) { - return virSecretDefParse(NULL, filename); + return virSecretDefParse(NULL, filename, flags); } =20 static int diff --git a/src/conf/secret_conf.h b/src/conf/secret_conf.h index 19f612b8fe..2a19629f54 100644 --- a/src/conf/secret_conf.h +++ b/src/conf/secret_conf.h @@ -38,8 +38,13 @@ struct _virSecretDef { }; =20 void virSecretDefFree(virSecretDefPtr def); -virSecretDefPtr virSecretDefParseString(const char *xml); -virSecretDefPtr virSecretDefParseFile(const char *filename); + +virSecretDefPtr virSecretDefParseString(const char *xml, + unsigned int flags); + +virSecretDefPtr virSecretDefParseFile(const char *filename, + unsigned int flags); + char *virSecretDefFormat(const virSecretDef *def); =20 # define VIR_CONNECT_LIST_SECRETS_FILTERS_EPHEMERAL \ diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 48ce3c8141..9527d7570e 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -909,7 +909,7 @@ virSecretLoad(virSecretObjListPtr secrets, virSecretDefPtr def =3D NULL; virSecretObjPtr obj =3D NULL; =20 - if (!(def =3D virSecretDefParseFile(path))) + if (!(def =3D virSecretDefParseFile(path, 0))) goto cleanup; =20 if (virSecretLoadValidateUUID(def, file) < 0) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 3c3557947e..5e1f82a314 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -218,7 +218,7 @@ secretDefineXML(virConnectPtr conn, =20 virCheckFlags(0, NULL); =20 - if (!(def =3D virSecretDefParseString(xml))) + if (!(def =3D virSecretDefParseString(xml, 0))) return NULL; =20 if (virSecretDefineXMLEnsureACL(conn, def) < 0) diff --git a/tests/secretxml2xmltest.c b/tests/secretxml2xmltest.c index 306f64c236..573edd6012 100644 --- a/tests/secretxml2xmltest.c +++ b/tests/secretxml2xmltest.c @@ -15,7 +15,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *o= utxml) int ret =3D -1; virSecretDefPtr secret =3D NULL; =20 - if (!(secret =3D virSecretDefParseFile(inxml))) + if (!(secret =3D virSecretDefParseFile(inxml, 0))) goto fail; =20 if (!(actual =3D virSecretDefFormat(secret))) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 07:45: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 1532976472073115.11641194882623; Mon, 30 Jul 2018 11:47:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3853030001EE; Mon, 30 Jul 2018 18:47:50 +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 050CAC8742; Mon, 30 Jul 2018 18:47:50 +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 9F69418052E9; Mon, 30 Jul 2018 18:47:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UIllgv000584 for ; Mon, 30 Jul 2018 14:47:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DAE0CA5C9; Mon, 30 Jul 2018 18:47:47 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-84.phx2.redhat.com [10.3.116.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 294FBD0F95 for ; Mon, 30 Jul 2018 18:47:29 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 14:46:45 -0400 Message-Id: <20180730184648.5059-9-jferlan@redhat.com> In-Reply-To: <20180730184648.5059-1-jferlan@redhat.com> References: <20180730184648.5059-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/11] conf: Disallow new secrets to use all white space as usage id 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.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 30 Jul 2018 18:47:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1107420 Add a new define/create flag VIR_SECRET_DEF_PARSE_VALIDATE_USAGE_ID to disallow new secrets to be defined/created using a usage id comprised entirely of spaces. Alter the secretxml2xmltest to add a parse failure scenario and a test in order to prove the failure occurs. Signed-off-by: John Ferlan --- src/conf/secret_conf.c | 10 ++++++- src/conf/secret_conf.h | 7 +++++ src/secret/secret_driver.c | 3 +- .../usage-whitespace-invalid.xml | 7 +++++ tests/secretxml2xmltest.c | 30 +++++++++++++++---- 5 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 tests/secretxml2xmlin/usage-whitespace-invalid.xml diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index d98a4f2442..9a77327014 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -130,7 +130,7 @@ virSecretDefParseXML(xmlXPathContextPtr ctxt, char *prop =3D NULL; char *uuidstr =3D NULL; =20 - virCheckFlags(0, NULL); + virCheckFlags(VIR_SECRET_DEF_PARSE_VALIDATE_USAGE_ID, NULL); =20 if (VIR_ALLOC(def) < 0) goto cleanup; @@ -183,6 +183,14 @@ virSecretDefParseXML(xmlXPathContextPtr ctxt, if (virXPathNode("./usage", ctxt) !=3D NULL && virSecretDefParseUsage(ctxt, def) < 0) goto cleanup; + + if (def->usage_id && (flags & VIR_SECRET_DEF_PARSE_VALIDATE_USAGE_ID) = && + virStringIsEmpty(def->usage_id)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("usage name must contain at least one non blank c= haracter")); + goto cleanup; + } + VIR_STEAL_PTR(ret, def); =20 cleanup: diff --git a/src/conf/secret_conf.h b/src/conf/secret_conf.h index 2a19629f54..b7aa70d785 100644 --- a/src/conf/secret_conf.h +++ b/src/conf/secret_conf.h @@ -39,6 +39,13 @@ struct _virSecretDef { =20 void virSecretDefFree(virSecretDefPtr def); =20 +typedef enum { + /* Perform extra name validation on new secret usage ids which + * will cause failure to parse the XML. Initially just that a + * name cannot be all white space. */ + VIR_SECRET_DEF_PARSE_VALIDATE_USAGE_ID =3D 1 << 0, +} virSecretDefParseFlags; + virSecretDefPtr virSecretDefParseString(const char *xml, unsigned int flags); =20 diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 5e1f82a314..2a66481d37 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -215,10 +215,11 @@ secretDefineXML(virConnectPtr conn, virSecretDefPtr backup =3D NULL; virSecretDefPtr def; virObjectEventPtr event =3D NULL; + unsigned int parse_flags =3D VIR_SECRET_DEF_PARSE_VALIDATE_USAGE_ID; =20 virCheckFlags(0, NULL); =20 - if (!(def =3D virSecretDefParseString(xml, 0))) + if (!(def =3D virSecretDefParseString(xml, parse_flags))) return NULL; =20 if (virSecretDefineXMLEnsureACL(conn, def) < 0) diff --git a/tests/secretxml2xmlin/usage-whitespace-invalid.xml b/tests/sec= retxml2xmlin/usage-whitespace-invalid.xml new file mode 100644 index 0000000000..7611bd53d1 --- /dev/null +++ b/tests/secretxml2xmlin/usage-whitespace-invalid.xml @@ -0,0 +1,7 @@ + + f52a81b2-424e-490c-823d-6bd4235bc572 + Ceph secret + + + + diff --git a/tests/secretxml2xmltest.c b/tests/secretxml2xmltest.c index 573edd6012..3c624d8319 100644 --- a/tests/secretxml2xmltest.c +++ b/tests/secretxml2xmltest.c @@ -9,14 +9,24 @@ #define VIR_FROM_THIS VIR_FROM_NONE =20 static int -testCompareXMLToXMLFiles(const char *inxml, const char *outxml) +testCompareXMLToXMLFiles(const char *inxml, + const char *outxml, + bool expect_parse_fail) { char *actual =3D NULL; int ret =3D -1; virSecretDefPtr secret =3D NULL; - - if (!(secret =3D virSecretDefParseFile(inxml, 0))) + unsigned int parse_flags =3D VIR_SECRET_DEF_PARSE_VALIDATE_USAGE_ID; + + if (!(secret =3D virSecretDefParseFile(inxml, parse_flags))) { + if (expect_parse_fail) { + VIR_TEST_DEBUG("Got expected parse failure msg=3D'%s'", + virGetLastErrorMessage()); + virResetLastError(); + ret =3D 0; + } goto fail; + } =20 if (!(actual =3D virSecretDefFormat(secret))) goto fail; @@ -35,6 +45,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *o= utxml) struct testInfo { const char *name; bool different; + bool expect_fail; }; =20 static int @@ -54,7 +65,7 @@ testCompareXMLToXMLHelper(const void *data) goto cleanup; } =20 - result =3D testCompareXMLToXMLFiles(inxml, outxml); + result =3D testCompareXMLToXMLFiles(inxml, outxml, info->expect_fail); =20 cleanup: VIR_FREE(inxml); @@ -68,19 +79,26 @@ mymain(void) { int ret =3D 0; =20 -#define DO_TEST(name) \ +#define DO_TEST_FULL(name, different, parse_fail) \ do { \ - const struct testInfo info =3D {name, false}; \ + const struct testInfo info =3D {name, different, parse_fail}; \ if (virTestRun("Secret XML->XML " name, \ testCompareXMLToXMLHelper, &info) < 0) \ ret =3D -1; \ } while (0) =20 +#define DO_TEST(name) \ + DO_TEST_FULL(name, false, false) + +#define DO_TEST_PARSE_FAIL(name) \ + DO_TEST_FULL(name, false, true) + DO_TEST("ephemeral-usage-volume"); DO_TEST("usage-volume"); DO_TEST("usage-ceph"); DO_TEST("usage-iscsi"); DO_TEST("usage-tls"); + DO_TEST_PARSE_FAIL("usage-whitespace-invalid"); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 07:45: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 153297650281172.99565035347882; Mon, 30 Jul 2018 11:48:22 -0700 (PDT) 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 1523D4E4C6; Mon, 30 Jul 2018 18:48:00 +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 C757E60190; Mon, 30 Jul 2018 18:47:59 +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 78B4E3FA54; Mon, 30 Jul 2018 18:47:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UIlweP000601 for ; Mon, 30 Jul 2018 14:47:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id F22ABD0937; Mon, 30 Jul 2018 18:47:57 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-84.phx2.redhat.com [10.3.116.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77134C6A0E for ; Mon, 30 Jul 2018 18:47:47 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 14:46:46 -0400 Message-Id: <20180730184648.5059-10-jferlan@redhat.com> In-Reply-To: <20180730184648.5059-1-jferlan@redhat.com> References: <20180730184648.5059-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/11] conf: Add @flags to NWFilter Def processing 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.38]); Mon, 30 Jul 2018 18:48:21 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a @flags argument when parsing the nwfilter definition via the virNWFilterDefParse{XML|Node|String|File} API's as this will allow us to in the future make parsing decisions based on the @flags. Signed-off-by: John Ferlan --- src/conf/nwfilter_conf.c | 25 ++++++++++++++++--------- src/conf/nwfilter_conf.h | 9 ++++++--- src/conf/virnwfilterobj.c | 2 +- src/nwfilter/nwfilter_driver.c | 2 +- tests/nwfilterxml2firewalltest.c | 2 +- tests/nwfilterxml2xmltest.c | 2 +- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 120ca5ec14..c1867fb946 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -2602,7 +2602,8 @@ virNWFilterIsAllowedChain(const char *chainname) =20 =20 static virNWFilterDefPtr -virNWFilterDefParseXML(xmlXPathContextPtr ctxt) +virNWFilterDefParseXML(xmlXPathContextPtr ctxt, + unsigned int flags) { virNWFilterDefPtr ret; xmlNodePtr curr =3D ctxt->node; @@ -2613,6 +2614,8 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) int chain_priority; const char *name_prefix; =20 + virCheckFlags(0, NULL); + if (VIR_ALLOC(ret) < 0) return NULL; =20 @@ -2734,7 +2737,8 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) =20 virNWFilterDefPtr virNWFilterDefParseNode(xmlDocPtr xml, - xmlNodePtr root) + xmlNodePtr root, + unsigned int flags) { xmlXPathContextPtr ctxt =3D NULL; virNWFilterDefPtr def =3D NULL; @@ -2753,7 +2757,7 @@ virNWFilterDefParseNode(xmlDocPtr xml, } =20 ctxt->node =3D root; - def =3D virNWFilterDefParseXML(ctxt); + def =3D virNWFilterDefParseXML(ctxt, flags); =20 cleanup: xmlXPathFreeContext(ctxt); @@ -2763,13 +2767,14 @@ virNWFilterDefParseNode(xmlDocPtr xml, =20 static virNWFilterDefPtr virNWFilterDefParse(const char *xmlStr, - const char *filename) + const char *filename, + unsigned int flags) { virNWFilterDefPtr def =3D NULL; xmlDocPtr xml; =20 if ((xml =3D virXMLParse(filename, xmlStr, _("(nwfilter_definition)"))= )) { - def =3D virNWFilterDefParseNode(xml, xmlDocGetRootElement(xml)); + def =3D virNWFilterDefParseNode(xml, xmlDocGetRootElement(xml), fl= ags); xmlFreeDoc(xml); } =20 @@ -2778,16 +2783,18 @@ virNWFilterDefParse(const char *xmlStr, =20 =20 virNWFilterDefPtr -virNWFilterDefParseString(const char *xmlStr) +virNWFilterDefParseString(const char *xmlStr, + unsigned int flags) { - return virNWFilterDefParse(xmlStr, NULL); + return virNWFilterDefParse(xmlStr, NULL, flags); } =20 =20 virNWFilterDefPtr -virNWFilterDefParseFile(const char *filename) +virNWFilterDefParseFile(const char *filename, + unsigned int flags) { - return virNWFilterDefParse(NULL, filename); + return virNWFilterDefParse(NULL, filename, flags); } =20 =20 diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h index 9f8ad51bf2..5ffdc07fab 100644 --- a/src/conf/nwfilter_conf.h +++ b/src/conf/nwfilter_conf.h @@ -561,7 +561,8 @@ virNWFilterDeleteDef(const char *configDir, =20 virNWFilterDefPtr virNWFilterDefParseNode(xmlDocPtr xml, - xmlNodePtr root); + xmlNodePtr root, + unsigned int flags); =20 char * virNWFilterDefFormat(const virNWFilterDef *def); @@ -571,10 +572,12 @@ virNWFilterSaveConfig(const char *configDir, virNWFilterDefPtr def); =20 virNWFilterDefPtr -virNWFilterDefParseString(const char *xml); +virNWFilterDefParseString(const char *xml, + unsigned int flags); =20 virNWFilterDefPtr -virNWFilterDefParseFile(const char *filename); +virNWFilterDefParseFile(const char *filename, + unsigned int flags); =20 void virNWFilterWriteLockFilterUpdates(void); diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c index 0136a0d56c..3993be3874 100644 --- a/src/conf/virnwfilterobj.c +++ b/src/conf/virnwfilterobj.c @@ -503,7 +503,7 @@ virNWFilterObjListLoadConfig(virNWFilterObjListPtr nwfi= lters, if (!(configFile =3D virFileBuildPath(configDir, name, ".xml"))) goto error; =20 - if (!(def =3D virNWFilterDefParseFile(configFile))) + if (!(def =3D virNWFilterDefParseFile(configFile, 0))) goto error; =20 if (STRNEQ(name, def->name)) { diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index ac3a964388..d850a66b28 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -556,7 +556,7 @@ nwfilterDefineXML(virConnectPtr conn, nwfilterDriverLock(); virNWFilterWriteLockFilterUpdates(); =20 - if (!(def =3D virNWFilterDefParseString(xml))) + if (!(def =3D virNWFilterDefParseString(xml, 0))) goto cleanup; =20 if (virNWFilterDefineXMLEnsureACL(conn, def) < 0) diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewallt= est.c index 043b7d170e..786761a04e 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -275,7 +275,7 @@ virNWFilterDefToInst(const char *xml, { size_t i; int ret =3D -1; - virNWFilterDefPtr def =3D virNWFilterDefParseFile(xml); + virNWFilterDefPtr def =3D virNWFilterDefParseFile(xml, 0); =20 if (!def) return -1; diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c index 89f809ca8f..0c79afa8ee 100644 --- a/tests/nwfilterxml2xmltest.c +++ b/tests/nwfilterxml2xmltest.c @@ -29,7 +29,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *o= utxml, =20 virResetLastError(); =20 - if (!(dev =3D virNWFilterDefParseFile(inxml))) { + if (!(dev =3D virNWFilterDefParseFile(inxml, 0))) { if (expect_error) { virResetLastError(); goto done; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 07:45: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 1532976503672265.34304035795174; Mon, 30 Jul 2018 11:48:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA88C30015F0; Mon, 30 Jul 2018 18:48:21 +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 A723F30BBD6B; Mon, 30 Jul 2018 18:48: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 671D53F7CB; Mon, 30 Jul 2018 18:48:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UImKIi000681 for ; Mon, 30 Jul 2018 14:48:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 717CDD033A; Mon, 30 Jul 2018 18:48:20 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-84.phx2.redhat.com [10.3.116.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD50FD0FC2 for ; Mon, 30 Jul 2018 18:47:53 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 14:46:47 -0400 Message-Id: <20180730184648.5059-11-jferlan@redhat.com> In-Reply-To: <20180730184648.5059-1-jferlan@redhat.com> References: <20180730184648.5059-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/11] conf: Disallow new nwfilters to use all white space as name 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 30 Jul 2018 18:48:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1107420 Add a new define/create flag VIR_NWFILTER_DEF_PARSE_VALIDATE_NAME to disallow new nwfilters to be defined/created using a name comprised entirely of spaces. Alter the nwfilterxml2xmltest to add a test in order to prove the failure occurs. Signed-off-by: John Ferlan --- src/conf/nwfilter_conf.c | 9 ++++++++- src/conf/nwfilter_conf.h | 7 +++++++ src/nwfilter/nwfilter_driver.c | 3 ++- tests/nwfilterxml2xmlin/name-whitespace-invalid.xml | 4 ++++ tests/nwfilterxml2xmltest.c | 7 ++++++- 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/nwfilterxml2xmlin/name-whitespace-invalid.xml diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index c1867fb946..4f99f88dca 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -2614,7 +2614,7 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt, int chain_priority; const char *name_prefix; =20 - virCheckFlags(0, NULL); + virCheckFlags(VIR_NWFILTER_DEF_PARSE_VALIDATE_NAME, NULL); =20 if (VIR_ALLOC(ret) < 0) return NULL; @@ -2626,6 +2626,13 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt, goto cleanup; } =20 + if ((flags & VIR_NWFILTER_DEF_PARSE_VALIDATE_NAME) && + virStringIsEmpty(ret->name)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("name must contain at least one non blank charact= er")); + goto cleanup; + } + chain_pri_s =3D virXPathString("string(./@priority)", ctxt); if (chain_pri_s) { if (virStrToLong_i(chain_pri_s, NULL, 10, &chain_priority) < 0) { diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h index 5ffdc07fab..2a7eabbf91 100644 --- a/src/conf/nwfilter_conf.h +++ b/src/conf/nwfilter_conf.h @@ -559,6 +559,13 @@ int virNWFilterDeleteDef(const char *configDir, virNWFilterDefPtr def); =20 +typedef enum { + /* Perform extra name validation on new nwfilter names which + * will cause failure to parse the XML. Initially just that a + * name cannot be all white space. */ + VIR_NWFILTER_DEF_PARSE_VALIDATE_NAME =3D 1 << 0, +} virNWFilterDefParseFlags; + virNWFilterDefPtr virNWFilterDefParseNode(xmlDocPtr xml, xmlNodePtr root, diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index d850a66b28..3529dfa519 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -546,6 +546,7 @@ nwfilterDefineXML(virConnectPtr conn, virNWFilterObjPtr obj =3D NULL; virNWFilterDefPtr objdef; virNWFilterPtr nwfilter =3D NULL; + unsigned int parse_flags =3D VIR_NWFILTER_DEF_PARSE_VALIDATE_NAME; =20 if (!driver->privileged) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -556,7 +557,7 @@ nwfilterDefineXML(virConnectPtr conn, nwfilterDriverLock(); virNWFilterWriteLockFilterUpdates(); =20 - if (!(def =3D virNWFilterDefParseString(xml, 0))) + if (!(def =3D virNWFilterDefParseString(xml, parse_flags))) goto cleanup; =20 if (virNWFilterDefineXMLEnsureACL(conn, def) < 0) diff --git a/tests/nwfilterxml2xmlin/name-whitespace-invalid.xml b/tests/nw= filterxml2xmlin/name-whitespace-invalid.xml new file mode 100644 index 0000000000..452847ae93 --- /dev/null +++ b/tests/nwfilterxml2xmlin/name-whitespace-invalid.xml @@ -0,0 +1,4 @@ + + 83011800-f663-96d6-8841-fd836b4318c6 + + diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c index 0c79afa8ee..de63ab1a91 100644 --- a/tests/nwfilterxml2xmltest.c +++ b/tests/nwfilterxml2xmltest.c @@ -26,11 +26,14 @@ testCompareXMLToXMLFiles(const char *inxml, const char = *outxml, char *actual =3D NULL; int ret =3D -1; virNWFilterDefPtr dev =3D NULL; + unsigned int parse_flags =3D VIR_NWFILTER_DEF_PARSE_VALIDATE_NAME; =20 virResetLastError(); =20 - if (!(dev =3D virNWFilterDefParseFile(inxml, 0))) { + if (!(dev =3D virNWFilterDefParseFile(inxml, parse_flags))) { if (expect_error) { + VIR_TEST_DEBUG("Got expected parse failure msg=3D'%s'", + virGetLastErrorMessage()); virResetLastError(); goto done; } @@ -149,6 +152,8 @@ mymain(void) =20 DO_TEST("ipset-test", false); =20 + DO_TEST("name-whitespace-invalid", true); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 07:45: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 1533456405980491.4691064423379; Sun, 5 Aug 2018 01:06:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 376C1308FB98; Sun, 5 Aug 2018 08:06:42 +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 5E00657DE6; Sun, 5 Aug 2018 08:06:37 +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 5CC4418037F0; Sun, 5 Aug 2018 08:06:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6UJjZTT009437 for ; Mon, 30 Jul 2018 15:45:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 159AB1824A; Mon, 30 Jul 2018 19:45:35 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-84.phx2.redhat.com [10.3.116.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE8006E527 for ; Mon, 30 Jul 2018 19:45:24 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 15:45:24 -0400 Message-Id: <20180730194524.10505-1-jferlan@redhat.com> In-Reply-To: <20180730184648.5059-1-jferlan@redhat.com> References: <20180730184648.5059-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/11] conf: Disallow new snapshots to use all white space as name 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Sun, 05 Aug 2018 08:06:44 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1107420 Add a new define/create flag VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE_NAME to disallow new snapshots to be defined/created using a name comprised entirely of spaces. Alter the domainsnapshotxml2xmltest to add a test in order to prove the failure occurs. Signed-off-by: John Ferlan --- Looks like the original send had a network glitch right at this patch so just making sure 11/11 makes it to the list (and hopefully as a reply to the 0/11 cover). src/conf/snapshot_conf.c | 7 ++++ src/conf/snapshot_conf.h | 1 + src/qemu/qemu_driver.c | 3 +- .../name_whitespace.xml | 3 ++ tests/domainsnapshotxml2xmltest.c | 38 ++++++++++++++----- 5 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 tests/domainsnapshotxml2xmlin/name_whitespace.xml diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index adba149241..2897a7edf5 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -235,6 +235,13 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, goto cleanup; } =20 + if ((flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE_NAME) && + virStringIsEmpty(def->name)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + ("name must contain at least one non blank characte= r")); + goto cleanup; + } + def->description =3D virXPathString("string(./description)", ctxt); =20 if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) { diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index 20a42bd572..2599c6b57f 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -101,6 +101,7 @@ typedef enum { VIR_DOMAIN_SNAPSHOT_PARSE_DISKS =3D 1 << 1, VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL =3D 1 << 2, VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE =3D 1 << 3, + VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE_NAME =3D 1 << 4, } virDomainSnapshotParseFlags; =20 virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 37f10d286e..b29faffee1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15279,7 +15279,8 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, virDomainSnapshotDefPtr def =3D NULL; bool update_current =3D true; bool redefine =3D flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE; - unsigned int parse_flags =3D VIR_DOMAIN_SNAPSHOT_PARSE_DISKS; + unsigned int parse_flags =3D VIR_DOMAIN_SNAPSHOT_PARSE_DISKS | + VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE_NAME; virDomainSnapshotObjPtr other =3D NULL; int align_location =3D VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL; bool align_match =3D true; diff --git a/tests/domainsnapshotxml2xmlin/name_whitespace.xml b/tests/doma= insnapshotxml2xmlin/name_whitespace.xml new file mode 100644 index 0000000000..901bcce62f --- /dev/null +++ b/tests/domainsnapshotxml2xmlin/name_whitespace.xml @@ -0,0 +1,3 @@ + + + diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xm= ltest.c index 5ea0f325de..046e8f7525 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -74,14 +74,16 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, const char *uuid, bool internal, - bool redefine) + bool redefine, + bool expect_parse_fail) { char *inXmlData =3D NULL; char *outXmlData =3D NULL; char *actual =3D NULL; int ret =3D -1; virDomainSnapshotDefPtr def =3D NULL; - unsigned int flags =3D VIR_DOMAIN_SNAPSHOT_PARSE_DISKS; + unsigned int flags =3D VIR_DOMAIN_SNAPSHOT_PARSE_DISKS | + VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE_NAME; =20 if (internal) flags |=3D VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL; @@ -97,8 +99,15 @@ testCompareXMLToXMLFiles(const char *inxml, =20 if (!(def =3D virDomainSnapshotDefParseString(inXmlData, driver.caps, driver.xmlopt, - flags))) + flags))) { + if (expect_parse_fail) { + VIR_TEST_DEBUG("Got expected parse failure msg=3D'%s'", + virGetLastErrorMessage()); + virResetLastError(); + ret =3D 0; + } goto cleanup; + } =20 if (!(actual =3D virDomainSnapshotDefFormat(uuid, def, driver.caps, driver.xmlopt, @@ -135,6 +144,7 @@ struct testInfo { const char *uuid; bool internal; bool redefine; + bool expect_parse_fail; }; =20 =20 @@ -144,7 +154,8 @@ testCompareXMLToXMLHelper(const void *data) const struct testInfo *info =3D data; =20 return testCompareXMLToXMLFiles(info->inxml, info->outxml, info->uuid, - info->internal, info->redefine); + info->internal, info->redefine, + info->expect_parse_fail); } =20 =20 @@ -168,11 +179,13 @@ mymain(void) } =20 =20 -# define DO_TEST(prefix, name, inpath, outpath, uuid, internal, redefine) \ +# define DO_TEST(prefix, name, inpath, outpath, uuid, internal, redefine, \ + expect_parse_fail) \ do { \ const struct testInfo info =3D {abs_srcdir "/" inpath "/" name ".x= ml", \ abs_srcdir "/" outpath "/" name ".xm= l", \ - uuid, internal, redefine}; \ + uuid, internal, redefine, \ + expect_parse_fail}; \ if (virTestRun("SNAPSHOT XML-2-XML " prefix " " name, \ testCompareXMLToXMLHelper, &info) < 0) \ ret =3D -1; \ @@ -181,18 +194,23 @@ mymain(void) # define DO_TEST_IN(name, uuid) DO_TEST("in->in", name,\ "domainsnapshotxml2xmlin",\ "domainsnapshotxml2xmlin",\ - uuid, false, false) + uuid, false, false, false) + +# define DO_TEST_IN_PARSE_FAIL(name, uuid) DO_TEST("in->in", name,\ + "domainsnapshotxml2xmlin",\ + "domainsnapshotxml2xmlin",\ + uuid, false, false, true) =20 # define DO_TEST_OUT(name, uuid, internal) DO_TEST("out->out", name,\ "domainsnapshotxml2xmlo= ut",\ "domainsnapshotxml2xmlo= ut",\ - uuid, internal, true) + uuid, internal, true, f= alse) =20 # define DO_TEST_INOUT(name, uuid, internal, redefine) \ DO_TEST("in->out", name,\ "domainsnapshotxml2xmlin",\ "domainsnapshotxml2xmlout",\ - uuid, internal, redefine) + uuid, internal, redefine, false) =20 /* Unset or set all envvars here that are copied in qemudBuildCommandL= ine * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected @@ -219,6 +237,8 @@ mymain(void) DO_TEST_IN("description_only", NULL); DO_TEST_IN("name_only", NULL); =20 + DO_TEST_IN_PARSE_FAIL("name_whitespace", NULL); + cleanup: if (testSnapshotXMLVariableLineRegex) regfree(testSnapshotXMLVariableLineRegex); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list