From nobody Sun Feb 8 10:50:33 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 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