Comment 5 for bug 1748019

Revision history for this message
Cole Robinson (crobinso) wrote :

I think libvirt can be extended here to workaround the conflict with something like:

diff --git a/src/util/virxml.c b/src/util/virxml.c
index 6e87605ea..248c5d7b2 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -810,9 +810,12 @@ virXMLParseHelper(int domcode,
     pctxt->sax->error = catchXMLError;

     if (filename) {
+ 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 |

That said, maybe lxml can do something similar too? Rather than register a libxml2 callback globally, only do it before entering the APIs that actually do file resolving. Seems there's only a few entry points for that, basically initial parsing and xinclude, but I didn't dig too deeply. Calling those functions shouldn't have much performance impact, they are just swapping pointers in C. I'm curious your thoughts