From nobody Mon Feb 9 02:52:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661516433; cv=none; d=zohomail.com; s=zohoarc; b=JquqRsp5p51REr7cunRmaHKVVIWW5rmhGEjOAtJeY7o8dKhkFfMlRKHRoPd1CKZGXULviz1Y2n6c0bzh3gL32awe7KnFEYcdga56DIczwU4JJHQwnQSKuoJdNtFVCiDOl/LfQFjAAAuEuKHgfYGnvQGlQ/uItz1jYIrIsg3MuNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661516433; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tBI8NAR0LlX7ZL8KsqJNELO4t618CjK61HsxTG9q1hc=; b=WTyL5DACo+H3qA7mIQN6iId1MD/gjx5tOprv7E5ZkwpMCWd6fVLEJA8Q/AyyqGn2fUdYszgUauECdGRRvhfCRqlLXE5/wSC0GMQ4SghDi7XhyyBlptt8pLd3cVPYB4n0dLjb8InOAqVZvcdrlEzNz/IEJaAPqslfOoO3kvXI14s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661516433802312.97578095874576; Fri, 26 Aug 2022 05:20:33 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-437-LDFa7N-SPXqKRApw4YpqPQ-1; Fri, 26 Aug 2022 08:20:21 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A6A6180231E; Fri, 26 Aug 2022 12:20:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91B202166B29; Fri, 26 Aug 2022 12:20:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 72D861946A4E; Fri, 26 Aug 2022 12:20:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 65FDC1946A43 for ; Fri, 26 Aug 2022 12:20:17 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5CA0F400EA8F; Fri, 26 Aug 2022 12:20:17 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA9C540CF916 for ; Fri, 26 Aug 2022 12:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661516432; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=tBI8NAR0LlX7ZL8KsqJNELO4t618CjK61HsxTG9q1hc=; b=Pmlfw2aisoUr5yQyuqO94gMwhDXDSQWxKEimSxYLsQN1nRqDkaFKgv8foVim8nzOHwrFuw irLOEWygenjIsEsBlUQIs9RFPvkvbFuP7RrU+deYZPyZScrcxAHMutCACjjOgswzFC+5wF v0W8nOjS5LFlMu5KFnV90Sl2idoUXzE= X-MC-Unique: LDFa7N-SPXqKRApw4YpqPQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/10] virDomainControllerDefParseXML: Return early if there's unexpectedly many elements Date: Fri, 26 Aug 2022 14:20:04 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661516434772100001 Content-Type: text/plain; charset="utf-8" Move some checks earlier so that they are not tucked at the back of the block of code doing the actual parsing. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 70672c83ce..a4384f9d13 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8181,7 +8181,12 @@ virDomainControllerDefParseXML(virDomainXMLOption *x= mlopt, return NULL; } - nmodelNodes =3D virXPathNodeSet("./model", ctxt, &modelNodes); + if ((nmodelNodes =3D virXPathNodeSet("./model", ctxt, &modelNodes)) > = 1) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Multiple elements in controller definiti= on not allowed")); + return NULL; + } + if (nmodelNodes =3D=3D 1) { if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { if (virXMLPropEnum(modelNodes[0], "name", @@ -8190,14 +8195,14 @@ virDomainControllerDefParseXML(virDomainXMLOption *= xmlopt, &def->opts.pciopts.modelName) < 0) return NULL; } - } else if (nmodelNodes > 1) { + } + + if ((ntargetNodes =3D virXPathNodeSet("./target", ctxt, &targetNodes))= > 1) { virReportError(VIR_ERR_XML_ERROR, "%s", - _("Multiple elements in " - "controller definition not allowed")); + _("Multiple elements in controller definit= ion not allowed")); return NULL; } - ntargetNodes =3D virXPathNodeSet("./target", ctxt, &targetNodes); if (ntargetNodes =3D=3D 1) { if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { if (virXMLPropInt(targetNodes[0], "chassisNr", 0, VIR_XML_PROP= _NONE, @@ -8230,11 +8235,6 @@ virDomainControllerDefParseXML(virDomainXMLOption *x= mlopt, def->opts.pciopts.targetIndex) < 0) return NULL; } - } else if (ntargetNodes > 1) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Multiple elements in " - "controller definition not allowed")); - return NULL; } /* node is parsed differently from target attributes because --=20 2.37.1