From nobody Sun Feb 8 17:36:36 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 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