From nobody Sun Feb 8 20:33:25 2026 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