From patchwork Fri Feb 23 23:21:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 129501 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1148161lja; Fri, 23 Feb 2018 15:21:24 -0800 (PST) X-Google-Smtp-Source: AG47ELviZv/b+p8m6aHcLMkfyXxkuFOKH/5L9uac3gDOQuQjRmaKHin8pMsPFC/QeB1OfB349kGE X-Received: by 10.157.51.100 with SMTP id u33mr2398775otd.26.1519428084162; Fri, 23 Feb 2018 15:21:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519428084; cv=none; d=google.com; s=arc-20160816; b=kaV5M3iA60uDUIZ+EVJN3zdeAIK7J7EPEV9g+lDo1JQZX6R/vSIr3RvBOnJfLszokV n1I2cJyn4/d788nMgOhSfUbHlxA7ruAPkKuF2t3m1CFKEjylb7LZijB3itTJawAoHcMe qk8meu4KzfhQYutlZMKGosaNLIgBg4glSrxraQogBY92cUShVWFI6zqD1Hd671usK41T ccjV9KZ3MaAZbhBzGn/QTUfnt9Yu9ludsefnNQGbPY+vuCe+g3IYtarvkhuUs1lBg9NP I9mPSLx9JNuj3Ls8QolLnod78eojmz7UA4QXmWe8XD/jYToyo3PpzLc+HFcLS1AiRqe/ EjOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=WoijvnrAAAHbDcwYS/RAKxh5e+ixziXrOBGHsuU1aR0=; b=hfzplNxs9+EhL3BqVigrCSINQIBhJYB43666URP/wq6YBuB3IfqHEmyodHnvqPKGiO u6TCCjaE0TNdoyZxo5U3ddDlRdIQOAdNBJ3eS8uKzyzAuR2OELFBB0siTFdGG2BR46Bm j1X+pKEw+8mRM19W4iFP4SFu+DOolcOXZ7Hn4ZvBOF7UfFV0Vyu55y8AJTA5e+XkzDE/ QpHuOmvvdsaiSAv0k9JAJklksNYU97/wwWB2z8LjCxn98hFnH8p1uNg0GQ/wlfYCa+Wv diw2TKEUH60JLL7vd5BDZClamh5P4jLALRD3LSu4LojumWB8j4ZzzabMsoFLSzK+2Fe7 oqSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id y32si1164127otd.405.2018.02.23.15.21.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Feb 2018 15:21:24 -0800 (PST) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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) Delivered-To: libvirt-list@redhat.com 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 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) 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=1544019 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(+) -- 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list 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 = catchXMLError; if (filename) { + /* Reset any libxml2 file callbacks, other libs (like python lxml) + * may have set their own which can get crashy */ + xmlExternalEntityLoader origloader = xmlGetExternalEntityLoader(); + xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader); xml = xmlCtxtReadFile(pctxt, filename, NULL, XML_PARSE_NONET | XML_PARSE_NOWARNING); + xmlSetExternalEntityLoader(origloader); } else { xml = xmlCtxtReadDoc(pctxt, BAD_CAST xmlStr, url, NULL, XML_PARSE_NONET |