From nobody Tue Dec 16 08:04:48 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1503302865460450.46711362890096; Mon, 21 Aug 2017 01:07:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6678D552FE; Mon, 21 Aug 2017 08:07: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 4328617AB7; Mon, 21 Aug 2017 08:07: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 A461E3FAEE; Mon, 21 Aug 2017 08:07:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7L87Riq002419 for ; Mon, 21 Aug 2017 04:07:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 92FD36F926; Mon, 21 Aug 2017 08:07:27 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AB566F924 for ; Mon, 21 Aug 2017 08:07:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6678D552FE Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Mon, 21 Aug 2017 10:07:05 +0200 Message-Id: <066a50686045fac4a4c4858dd87ae7fe59b2c79d.1503302799.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/17] conf: error out for multiple source elements while parsing chardev 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 21 Aug 2017 08:07:43 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently we accept and correctly parse this chardev XML: ... ... The parsed formatted XML is: ... ... That behavior is super wrong and should not be allowed. If you notice the current parse takes the first found attribute and uses that value, so for example from the "" only the "host" attribute is used. It works the same way for all possible attributes that we are able to parse for source element. This patch enforces providing only one source element for all character devices, only for UDP type we allow to provide two source elements since you can specify both modes. Signed-off-by: Pavel Hrdina --- src/conf/domain_conf.c | 17 ++++++++++++++ .../generic-chardev-tcp-multiple-source.xml | 26 ++++++++++++++++++= ++++ .../generic-chardev-udp-multiple-source.xml | 26 ++++++++++++++++++= ++++ tests/genericxml2xmltest.c | 4 ++++ 4 files changed, 73 insertions(+) create mode 100644 tests/genericxml2xmlindata/generic-chardev-tcp-multiple= -source.xml create mode 100644 tests/genericxml2xmlindata/generic-chardev-udp-multiple= -source.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ba0241cb21..651a049cf1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10917,12 +10917,29 @@ virDomainChrSourceDefParseXML(virDomainChrSourceD= efPtr def, char *append =3D NULL; char *haveTLS =3D NULL; char *tlsFromConfig =3D NULL; + int sourceParsed =3D 0; =20 for (; cur; cur =3D cur->next) { if (cur->type !=3D XML_ELEMENT_NODE) continue; =20 if (virXMLNodeNameEqual(cur, "source")) { + /* Parse only the first source element since only one is used + * for chardev devices, the only exception is UDP type, where + * user can specify two source elements. */ + if (sourceParsed >=3D 1 && def->type !=3D VIR_DOMAIN_CHR_TYPE_= UDP) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("only one source element is allowed for " + "character device")); + goto error; + } else if (sourceParsed >=3D 2) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("only two source elements are allowed for= " + "character device")); + goto error; + } + sourceParsed++; + if (!mode) mode =3D virXMLPropString(cur, "mode"); if (!haveTLS) diff --git a/tests/genericxml2xmlindata/generic-chardev-tcp-multiple-source= .xml b/tests/genericxml2xmlindata/generic-chardev-tcp-multiple-source.xml new file mode 100644 index 0000000000..bb8592aa4f --- /dev/null +++ b/tests/genericxml2xmlindata/generic-chardev-tcp-multiple-source.xml @@ -0,0 +1,26 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + + + + + + diff --git a/tests/genericxml2xmlindata/generic-chardev-udp-multiple-source= .xml b/tests/genericxml2xmlindata/generic-chardev-udp-multiple-source.xml new file mode 100644 index 0000000000..2b87a1bfaa --- /dev/null +++ b/tests/genericxml2xmlindata/generic-chardev-udp-multiple-source.xml @@ -0,0 +1,26 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + + + + + + diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 7dc137ed16..03913a68c9 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -110,9 +110,13 @@ mymain(void) TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); DO_TEST_FULL("chardev-tcp-missing-service", 0, false, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); + DO_TEST_FULL("chardev-tcp-multiple-source", 0, false, + TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); DO_TEST_DIFFERENT("chardev-udp"); DO_TEST_FULL("chardev-udp-missing-connect-service", 0, false, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); + DO_TEST_FULL("chardev-udp-multiple-source", 0, false, + TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); DO_TEST_DIFFERENT("chardev-unix"); DO_TEST_FULL("chardev-unix-smartcard-missing-path", 0, false, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list