From nobody Sat May 4 19:51:31 2024 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 1519428084264590.407575711187; Fri, 23 Feb 2018 15:21:24 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id EAE8A37E74; Fri, 23 Feb 2018 23:21:22 +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 425FB5D70A; Fri, 23 Feb 2018 23:21:22 +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 6BF4E18033EA; Fri, 23 Feb 2018 23:21:21 +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 w1NNLJdh019031 for ; Fri, 23 Feb 2018 18:21:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id A287A605DC; Fri, 23 Feb 2018 23:21:19 +0000 (UTC) Received: from worklaptop.redhat.com (ovpn-116-122.phx2.redhat.com [10.3.116.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DE5360462; Fri, 23 Feb 2018 23:21:17 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 23 Feb 2018 18:21:15 -0500 Message-Id: <5f7378fda41cb0f60ce1a0c59fb3717d04556d45.1519428075.git.crobinso@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util: xml: Don't conflict with other libxml2 user callbacks 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 23 Feb 2018 23:21:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" lxml is a popular python XML processing library. It uses libxml2 behind the scenes, and registers custom callbacks via xmlSetExternalEntityLoader. However this can cause crashes if if an app uses both lxml and libxml2 together in the same process. This is a known limitation of lxml and libxml2 generally. It also prevents us from using lxml in virt-manager: https://bugzilla.redhat.com/show_bug.cgi?id=3D1544019 However it's easy enough to work around in libvirt, by unsetting the EntityLoader callback to a known state before we ask libxml2 to parse a file from disk. Signed-off-by: Cole Robinson --- src/util/virxml.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/virxml.c b/src/util/virxml.c index 6e87605ea..3e01794f9 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -810,9 +810,14 @@ virXMLParseHelper(int domcode, pctxt->sax->error =3D catchXMLError; =20 if (filename) { + /* Reset any libxml2 file callbacks, other libs (like python lxml) + * may have set their own which can get crashy */ + xmlExternalEntityLoader origloader =3D xmlGetExternalEntityLoader(= ); + xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader); xml =3D xmlCtxtReadFile(pctxt, filename, NULL, XML_PARSE_NONET | XML_PARSE_NOWARNING); + xmlSetExternalEntityLoader(origloader); } else { xml =3D xmlCtxtReadDoc(pctxt, BAD_CAST xmlStr, url, NULL, XML_PARSE_NONET | --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list