[PATCH v2 2/3] util/xml: don't assume libxml2 has the filename of the document

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The libxml2 error handling gets the filename from a libxml2 struct, but
it is better to not assume libxml2 knows the filename being parsed, as
we might have simply provided it a pre-loaded string.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/util/virxml.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/util/virxml.c b/src/util/virxml.c
index 91f736bf39..797aa6f6ca 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -46,6 +46,7 @@
 /* Internal data to be passed to SAX parser and used by error handler. */
 struct virParserData {
     int domcode;
+    const char *filename;
 };
 
 
@@ -1022,7 +1023,7 @@ static void
 catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...)
 {
     xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
+    struct virParserData *private = ctxt->_private;
     const xmlChar *cur, *base;
     unsigned int n, col;        /* GCC warns if signed, because compared with sizeof() */
     int domcode = VIR_FROM_XML;
@@ -1030,6 +1031,10 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...)
     g_autofree char *contextstr = NULL;
     g_autofree char *pointerstr = NULL;
     const xmlError *lastError = xmlCtxtGetLastError(ctxt);
+    const char *filename = NULL;
+
+    if (private)
+        filename = private->filename;
 
     /* conditions for error printing */
     if (!ctxt ||
@@ -1040,9 +1045,8 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...)
         lastError->message == NULL)
         return;
 
-    if (ctxt->_private)
-        domcode = ((struct virParserData *) ctxt->_private)->domcode;
-
+    if (private)
+        domcode = private->domcode;
 
     cur = ctxt->input->cur;
     base = ctxt->input->base;
@@ -1083,10 +1087,10 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...)
 
     pointerstr = virBufferContentAndReset(&buf);
 
-    if (lastError->file) {
+    if (filename) {
         virGenericReportError(domcode, VIR_ERR_XML_DETAIL,
                               _("%1$s:%2$d: %3$s%4$s\n%5$s"),
-                              lastError->file,
+                              filename,
                               lastError->line,
                               lastError->message,
                               contextstr,
@@ -1152,6 +1156,7 @@ virXMLParseHelper(int domcode,
         abort();
 
     private.domcode = domcode;
+    private.filename = filename;
     pctxt->_private = &private;
     pctxt->sax->error = catchXMLError;
 
-- 
2.46.0




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux