From nobody Fri May 17 11:58:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1618476072; cv=none; d=zohomail.com; s=zohoarc; b=DIESwfKtqTF/dSjmyxcevVVhVCfxCZjU4aPapFfvuC/S8nqvWEDtE004x1mipPTyK6B5en999TgPHx9s+O1XSfj1ob2R+Ck9dc4Jcw28tz6Sf5kpSRjkKjy8wa/LxV6fk6toHGF/8++k3G7i5Df2RvsuR77sr5X5CyS37gYV7c4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618476072; h=Content-Type:Content-Transfer-Encoding:Cc: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=/EHZ1e9dDiSqAqK9N5YJxe4iSNVMR7YpvyI2iX0nCo8=; b=lW95oD7BRJIbfIu+cwmxtfHBwP6ZZZH8nGFB+u+ma7VJrGkpl+p8vnQxWVqT4z8PvwASrku9mw+j7IVJyOLNQJ5AwNlMYkvpwxuXM4iu6JQ54yTVtoSKX+pcXlI8XBsg7lM0t+83hpX/ZJINhPuFxLM7IKxCheosMOueVldpXUQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618476072088264.84507095675326; Thu, 15 Apr 2021 01:41:12 -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-579-A1oHW-0PPtOFFKZDOMjZ3w-1; Thu, 15 Apr 2021 04:41:08 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DCE8B802B4F; Thu, 15 Apr 2021 08:41:02 +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 B8F406267E; Thu, 15 Apr 2021 08:41:02 +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 7812A1806D17; Thu, 15 Apr 2021 08:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13F8exuf021233 for ; Thu, 15 Apr 2021 04:40:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id D5E615D76F; Thu, 15 Apr 2021 08:40:59 +0000 (UTC) Received: from work.redhat.com (ovpn-114-212.ams2.redhat.com [10.36.114.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D85D62462; Thu, 15 Apr 2021 08:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618476071; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=/EHZ1e9dDiSqAqK9N5YJxe4iSNVMR7YpvyI2iX0nCo8=; b=FVMF7Pp6x5EaU3+OmkN+OL4hWgtXE7FSUQr5CVciZ/bxxiOPHnoeF/JZ7X7mt+DbRDvSAn CSVv5OiPU/GX/gSBHMinFtRYY2/VJMcY9YHAmc0Uq8yYFodEfOPOPQ3GXYKPASFOgTONuR ilPaTpjsMvUkwNL1IiWXJR9Oqv77Efg= X-MC-Unique: A1oHW-0PPtOFFKZDOMjZ3w-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 1/2] virxml: Fix schema validation of individual nodes Date: Thu, 15 Apr 2021 10:40:53 +0200 Message-Id: <20210415084054.9971-2-twiederh@redhat.com> In-Reply-To: <20210415084054.9971-1-twiederh@redhat.com> References: <20210415084054.9971-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.15 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" xmlDocSetRootElement removes the node from its previous document tree, effectively removing the "" node from "" in virCPUDefParseXML. Signed-off-by: Tim Wiederhake --- src/util/virxml.c | 13 ++++++------- src/util/virxml.h | 1 - 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 117f50f2bf..d816a8e08d 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1285,16 +1285,15 @@ virXMLValidateAgainstSchema(const char *schemafile, =20 =20 int -virXMLValidateNodeAgainstSchema(const char *schemafile, - xmlDocPtr doc, - xmlNodePtr node) +virXMLValidateNodeAgainstSchema(const char *schemafile, xmlNodePtr node) { - xmlNodePtr root; int ret; + xmlDocPtr copy =3D xmlNewDoc(NULL); =20 - root =3D xmlDocSetRootElement(doc, node); - ret =3D virXMLValidateAgainstSchema(schemafile, doc); - xmlDocSetRootElement(doc, root); + xmlDocSetRootElement(copy, xmlCopyNode(node, true)); + ret =3D virXMLValidateAgainstSchema(schemafile, copy); + + xmlFreeDoc(copy); return ret; } =20 diff --git a/src/util/virxml.h b/src/util/virxml.h index de171dce12..8a8ec2a6df 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -213,7 +213,6 @@ virXMLValidateAgainstSchema(const char *schemafile, =20 int virXMLValidateNodeAgainstSchema(const char *schemafile, - xmlDocPtr doc, xmlNodePtr node); =20 void --=20 2.26.2 From nobody Fri May 17 11:58:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1618476124; cv=none; d=zohomail.com; s=zohoarc; b=XWqhj178ETzB6YiTjMgHFHsk8bfdJR4dXMxAPu7uty1yKNK/27VeJAGAAcB6yghjyFpBNd/7TxAVBFvHe7n+bbfpkgUOSU+XeZvAoauiTgJhSqVymXubnIJUTfbAAmd2Cp7cuycm7j5wFWLhVNfwyhYn76F2ZU6HGWyNLuczyG8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618476124; h=Content-Type:Content-Transfer-Encoding:Cc: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=DM1ORXv/yuKOcv5igCLzDe8urcvI5sBvlJ7OKIwaMok=; b=EOsxk9OXclEcoWdS6FBFwHl/LR4WAREx1VjUldJX1pn6yX++FMcO6j3orj6Mfdk7fv0ehrxwNI2gvFt2836EzhwKXvn6cqHPHT+8AkTqTQCBbsg9rJv7jfibocUB5j1l5/YLC9uylC/t6GFtfb2+7hpBgHdAVjNySygo8wv7usk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618476124791688.7762900169845; Thu, 15 Apr 2021 01:42:04 -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-579-bA7tBCvMP_GkFaMGE-NASw-1; Thu, 15 Apr 2021 04:41:08 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 18D6418B9ED1; Thu, 15 Apr 2021 08:41:03 +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 DD7B910016DB; Thu, 15 Apr 2021 08:41:02 +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 9DB0D1806D18; Thu, 15 Apr 2021 08:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13F8f051021243 for ; Thu, 15 Apr 2021 04:41:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id E0E7E5D76F; Thu, 15 Apr 2021 08:41:00 +0000 (UTC) Received: from work.redhat.com (ovpn-114-212.ams2.redhat.com [10.36.114.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3473362462; Thu, 15 Apr 2021 08:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618476123; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=DM1ORXv/yuKOcv5igCLzDe8urcvI5sBvlJ7OKIwaMok=; b=OPQir+lstZQRtcj5tsp9X9D/2XDdwGKE6uWfm8BNoMO0fZ8q/MjvRg1ebACZejCg6+IaKg g66NjJl2yNUsmwT79F6P6NlF+5vQk1W6Y+vqhUvMMIvFI9epaMkYbFvu71fJrr8nsktzgc l9IYiGZ1yU44PyJ/whaSDE7rFMuoTCo= X-MC-Unique: bA7tBCvMP_GkFaMGE-NASw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] virCPUDefParseXML: Log schema validation errors Date: Thu, 15 Apr 2021 10:40:54 +0200 Message-Id: <20210415084054.9971-3-twiederh@redhat.com> In-Reply-To: <20210415084054.9971-1-twiederh@redhat.com> References: <20210415084054.9971-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.84 on 10.5.11.22 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" Schema validation was only performed if the "validateXML" flag was set. Make invalid XML visible in the logs by always validating, but only treat validation errors as errors if said flag is set. Signed-off-by: Tim Wiederhake --- src/conf/cpu_conf.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index c095ab0e89..c584b0f360 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -329,6 +329,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, VIR_XPATH_NODE_AUTORESTORE(ctxt) int n; size_t i; + g_autofree char *schemafile =3D NULL; g_autofree char *cpuMode =3D NULL; g_autofree char *fallback =3D NULL; g_autofree char *vendor_id =3D NULL; @@ -347,16 +348,13 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, return -1; } =20 - if (validateXML) { - g_autofree char *schemafile =3D NULL; - - if (!(schemafile =3D virFileFindResource("cpu.rng", - abs_top_srcdir "/docs/schem= as", - PKGDATADIR "/schemas"))) - return -1; + if (!(schemafile =3D virFileFindResource("cpu.rng", + abs_top_srcdir "/docs/schemas", + PKGDATADIR "/schemas"))) + return -1; =20 - if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->doc, - ctxt->node) < 0) + if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->node) < 0) { + if (validateXML) return -1; } =20 --=20 2.26.2