]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util/xml: fix extraction of XML context
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 9 Aug 2024 10:28:24 +0000 (11:28 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 20 Dec 2024 10:00:22 +0000 (10:00 +0000)
Currently given an input of '<dom\n' we emit an error:

  error: Failed to define domain from tests/qemuxmlconfdata/broken-xml-invalid.xml
  error: at line 2: Couldn't find end of Start Tag dom line 1
  (null)
  ^

With this fix we emit:

  error: Failed to define domain from tests/qemuxmlconfdata/broken-xml-invalid.xml
  error: at line 2: Couldn't find end of Start Tag dom line 1
  <dom
  ----^

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virxml.c
tests/qemuxmlconfdata/broken-xml-invalid.x86_64-latest.err

index 51173303fee989978341fc1be6f5a36faeee6c98..38baeec5bb00de371d7c72fffacaf6d80de4edf7 100644 (file)
@@ -1047,6 +1047,11 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...)
     cur = ctxt->input->cur;
     base = ctxt->input->base;
 
+    /* skip backwards over NUL terminator, in case we failed
+     * parsing at the EOF position */
+    if ((cur > base) && *cur == '\0')
+        cur--;
+
     /* skip backwards over any end-of-lines */
     while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r')))
         cur--;
index 35a1801371d018ff9bc421eaad21ee4c402a53a1..a3bacd5d3a7640bcf06ce0bc858f77aae273fb33 100644 (file)
@@ -1,3 +1,3 @@
 ABS_SRCDIR/qemuxmlconfdata/broken-xml-invalid.xml:2: Couldn't find end of Start Tag dom line 1
-(null)
-^
+<dom
+----^