util/xml: fix extraction of XML context

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>
This commit is contained in:
Daniel P. Berrangé 2024-08-09 11:28:24 +01:00
parent f7cbb136c3
commit 0635cd9555
2 changed files with 7 additions and 2 deletions

View File

@ -1047,6 +1047,11 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...)
cur = ctxt->input->cur; cur = ctxt->input->cur;
base = ctxt->input->base; 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 */ /* skip backwards over any end-of-lines */
while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r')))
cur--; cur--;

View File

@ -1,3 +1,3 @@
ABS_SRCDIR/qemuxmlconfdata/broken-xml-invalid.xml:2: Couldn't find end of Start Tag dom line 1 ABS_SRCDIR/qemuxmlconfdata/broken-xml-invalid.xml:2: Couldn't find end of Start Tag dom line 1
(null) <dom
^ ----^