xmlParserCtxt->lastError was deprecated in libxml2 v2.13.0-103-g1228b4e0
xmlCtxtGetLastError(xmlParserCtxt) should be used instead
Signed-off-by: Jakub Palacky <jpalacky@redhat.com>
---
src/util/virxml.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/util/virxml.c b/src/util/virxml.c
index a7b75fd7b3..b72b63f55f 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -1035,8 +1035,8 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...)
if (!ctxt ||
(virGetLastErrorCode()) ||
ctxt->input == NULL ||
- ctxt->lastError.level != XML_ERR_FATAL ||
- ctxt->lastError.message == NULL)
+ xmlCtxtGetLastError(ctxt)->level != XML_ERR_FATAL ||
+ xmlCtxtGetLastError(ctxt)->message == NULL)
return;
if (ctxt->_private)
@@ -1078,19 +1078,19 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...)
pointerstr = virBufferContentAndReset(&buf);
- if (ctxt->lastError.file) {
+ if (xmlCtxtGetLastError(ctxt)->file) {
virGenericReportError(domcode, VIR_ERR_XML_DETAIL,
_("%1$s:%2$d: %3$s%4$s\n%5$s"),
- ctxt->lastError.file,
- ctxt->lastError.line,
- ctxt->lastError.message,
+ xmlCtxtGetLastError(ctxt)->file,
+ xmlCtxtGetLastError(ctxt)->line,
+ xmlCtxtGetLastError(ctxt)->message,
contextstr,
pointerstr);
} else {
virGenericReportError(domcode, VIR_ERR_XML_DETAIL,
_("at line %1$d: %2$s%3$s\n%4$s"),
- ctxt->lastError.line,
- ctxt->lastError.message,
+ xmlCtxtGetLastError(ctxt)->line,
+ xmlCtxtGetLastError(ctxt)->message,
contextstr,
pointerstr);
}
--
2.46.0
On 9/11/24 15:37, Jakub Palacky wrote:
> xmlParserCtxt->lastError was deprecated in libxml2 v2.13.0-103-g1228b4e0
> xmlCtxtGetLastError(xmlParserCtxt) should be used instead
>
> Signed-off-by: Jakub Palacky <jpalacky@redhat.com>
> ---
> src/util/virxml.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/src/util/virxml.c b/src/util/virxml.c
> index a7b75fd7b3..b72b63f55f 100644
> --- a/src/util/virxml.c
> +++ b/src/util/virxml.c
> @@ -1035,8 +1035,8 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...)
> if (!ctxt ||
> (virGetLastErrorCode()) ||
> ctxt->input == NULL ||
> - ctxt->lastError.level != XML_ERR_FATAL ||
> - ctxt->lastError.message == NULL)
> + xmlCtxtGetLastError(ctxt)->level != XML_ERR_FATAL ||
> + xmlCtxtGetLastError(ctxt)->message == NULL)
Looking at xmlCtxtGetLastError() it can return NULL. From parseInternals.c:
const xmlError *
xmlCtxtGetLastError(void *ctx)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if (ctxt == NULL)
return (NULL);
if (ctxt->lastError.code == XML_ERR_OK)
return (NULL);
return (&ctxt->lastError);
}
Now, ctxt == NULL is checked for by us, so that shouldn't happen. But
ctxt->lasterror.code == XML_ERR_OK could happen, though - this is in a
callback function that's supposed to be called when an error occurred.
Nevertheless, I'd feel a bit safer if xmlCtxtGetLastError()'s retval was
checked for before dereferencing it.
Michal
© 2016 - 2026 Red Hat, Inc.