From nobody Mon Feb 9 09:08:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1618587566; cv=none; d=zohomail.com; s=zohoarc; b=L9cJ4rbL6wYCD94gxG09Y3ujW/03b8YGL/j3qGMDoQy1OYavJLoF9Pn6rJd5qCHzuVbKiZ5D3p3nWcmn8LvxGXPv2SRxj8MdfA0wrxP5lEA7wny4OBD870fFD6DXJO+pI4HrPWqSqNHiwN3TnP2YLgo1rKTgIKWcNjBl2udmPnE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618587566; 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=UkEUZjU5GafPbCFWR5eOL8WVyRSnmi8TDorc9HZBDds=; b=HA8zmG2RFI/FKPz+Ni1o9zsXkP0D47qqBj/1a/Go3DYYGCFgpHIJczA/Qi/y/4WCvj2D1nOQdcaMDEvHNl4PqoXMBnZMTYGFSeiMyb6Yq8Iiqhn+Ng1T5KQPHiXsUV5cFuKhyy8RCl4RpyuOXBlX07MIXBkoO9vyICAR/J9BKjg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1618587566516121.30581196159869; Fri, 16 Apr 2021 08:39:26 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-278-d-dJi3LxMvqbE0Rt0AmXXA-1; Fri, 16 Apr 2021 11:39:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2003818BA286; Fri, 16 Apr 2021 15:39:18 +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 EDE5A5C260; Fri, 16 Apr 2021 15:39:17 +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 B992D1806D15; Fri, 16 Apr 2021 15:39:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13GFYpki009226 for ; Fri, 16 Apr 2021 11:34:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5579C1C4; Fri, 16 Apr 2021 15:34:51 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84EC05C3DF for ; Fri, 16 Apr 2021 15:34:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618587565; 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=UkEUZjU5GafPbCFWR5eOL8WVyRSnmi8TDorc9HZBDds=; b=Wk/sAGTiANBcTJ2kXHUe7UvaoQPimYtyYXZHHePlyg2n0+yq2RWvzrXbhdAp4wDSoB3Qsq czr2FumlIMxAv3lSYAFPhepm3VTU2Rmokw7BiCS8GOn3dHc217TRmlOZV/GTQEpjVEekPr FR5/oqBUsxV465LcgWrMv6hO4SsfG0s= X-MC-Unique: d-dJi3LxMvqbE0Rt0AmXXA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/25] util: xml: Introduce virXMLParseStringCtxtRoot Date: Fri, 16 Apr 2021 17:34:20 +0200 Message-Id: <8d2913f634b7843898a84e12e1f4d3639f824dc1.1618587222.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use the new macro instead of virXMLParseStringCtxt in places where the root node is being validated. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 9 +-------- src/conf/storage_conf.c | 16 +++++----------- src/util/virxml.h | 4 ++++ 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 17bbeddec6..6795f0b3be 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16438,16 +16438,9 @@ virDomainDiskDefParse(const char *xmlStr, g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; - if (!(xml =3D virXMLParseStringCtxt(xmlStr, _("(disk_definition)"), &c= txt))) + if (!(xml =3D virXMLParseStringCtxtRoot(xmlStr, _("(disk_definition)")= , "disk", &ctxt))) return NULL; - if (!virXMLNodeNameEqual(ctxt->node, "disk")) { - virReportError(VIR_ERR_XML_ERROR, - _("expecting root element of 'disk', not '%s'"), - ctxt->node->name); - return NULL; - } - return virDomainDiskDefParseXML(xmlopt, ctxt->node, ctxt, flags); } diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 66419616da..328650bd6a 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -691,25 +691,19 @@ virStoragePoolDefParseSourceString(const char *srcSpe= c, int pool_type) { g_autoptr(xmlDoc) doc =3D NULL; - xmlNodePtr node =3D NULL; g_autoptr(xmlXPathContext) xpath_ctxt =3D NULL; g_autoptr(virStoragePoolSource) def =3D NULL; - if (!(doc =3D virXMLParseStringCtxt(srcSpec, - _("(storage_source_specification)"), - &xpath_ctxt))) + if (!(doc =3D virXMLParseStringCtxtRoot(srcSpec, + _("(storage_source_specification= )"), + "source", + &xpath_ctxt))) return NULL; def =3D g_new0(virStoragePoolSource, 1); - if (!(node =3D virXPathNode("/source", xpath_ctxt))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("root element was not source")); - return NULL; - } - if (virStoragePoolDefParseSource(xpath_ctxt, def, pool_type, - node) < 0) + xpath_ctxt->node) < 0) return NULL; return g_steal_pointer(&def); diff --git a/src/util/virxml.h b/src/util/virxml.h index 38da2931a4..2b40398eee 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -221,6 +221,10 @@ virXMLPickShellSafeComment(const char *str1, #define virXMLParseStringCtxt(xmlStr, url, pctxt) \ virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, NULL, pctxt) +/* virXMLParseStringCtxtRoot is same as above, except it also validates ro= ot node name */ +#define virXMLParseStringCtxtRoot(xmlStr, url, rootnode, pctxt) \ + virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, rootnode, pctxt) + /** * virXMLParseFileCtxt: * @filename: file to parse --=20 2.30.2