From 0635cd9555ede02326afd274e8189ed3b70c1334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Fri, 9 Aug 2024 11:28:24 +0100 Subject: [PATCH] util/xml: fix extraction of XML context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently given an input of ' Reviewed-by: Richard W.M. Jones Signed-off-by: Daniel P. Berrangé --- src/util/virxml.c | 5 +++++ tests/qemuxmlconfdata/broken-xml-invalid.x86_64-latest.err | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 51173303fe..38baeec5bb 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -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--; diff --git a/tests/qemuxmlconfdata/broken-xml-invalid.x86_64-latest.err b/tests/qemuxmlconfdata/broken-xml-invalid.x86_64-latest.err index 35a1801371..a3bacd5d3a 100644 --- a/tests/qemuxmlconfdata/broken-xml-invalid.x86_64-latest.err +++ b/tests/qemuxmlconfdata/broken-xml-invalid.x86_64-latest.err @@ -1,3 +1,3 @@ ABS_SRCDIR/qemuxmlconfdata/broken-xml-invalid.xml:2: Couldn't find end of Start Tag dom line 1 -(null) -^ +