1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-27 14:03:36 +03:00

error: Fix direct invocation of SAX error handlers

Revert part of commit c5a8aef2 to make it safe to call the default SAX
error handlers directly. This has been deprecated for a long time but
even xmllint still uses these handlers.

Should fix #713.
This commit is contained in:
Nick Wellnhofer 2024-04-09 16:54:02 +02:00
parent 20fca2bb3d
commit fd8a35114f

67
error.c
View File

@ -729,7 +729,12 @@ xmlVRaiseError(xmlStructuredErrorFunc schannel,
} else if (xmlStructuredError != NULL) {
xmlStructuredError(xmlStructuredErrorContext, to);
} else if (channel != NULL) {
if ((ctxt == NULL) && (channel == xmlGenericErrorDefaultFunc))
/* Don't invoke legacy error handlers */
if ((channel == xmlGenericErrorDefaultFunc) ||
(channel == xmlParserError) ||
(channel == xmlParserWarning) ||
(channel == xmlParserValidityError) ||
(channel == xmlParserValidityWarning))
xmlFormatError(to, xmlGenericError, xmlGenericErrorContext);
else
channel(data, "%s", to->message);
@ -784,6 +789,42 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel,
return(res);
}
static void
xmlVFormatLegacyError(void *ctx, const char *level,
const char *fmt, va_list ap) {
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr input = NULL;
xmlParserInputPtr cur = NULL;
xmlChar *str = NULL;
if (ctxt != NULL) {
input = ctxt->input;
if ((input != NULL) && (input->filename == NULL) &&
(ctxt->inputNr > 1)) {
cur = input;
input = ctxt->inputTab[ctxt->inputNr - 2];
}
xmlParserPrintFileInfo(input);
}
xmlGenericError(xmlGenericErrorContext, "%s: ", level);
xmlStrVASPrintf(&str, MAX_ERR_MSG_SIZE, fmt, ap);
if (str != NULL) {
xmlGenericError(xmlGenericErrorContext, "%s", (char *) str);
xmlFree(str);
}
if (ctxt != NULL) {
xmlParserPrintFileContext(input);
if (cur != NULL) {
xmlParserPrintFileInfo(cur);
xmlGenericError(xmlGenericErrorContext, "\n");
xmlParserPrintFileContext(cur);
}
}
}
/**
* xmlParserError:
* @ctx: an XML parser context
@ -796,9 +837,11 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel,
void
xmlParserError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
{
xmlParserCtxtPtr ctxt = ctx;
va_list ap;
xmlFormatError(&ctxt->lastError, xmlGenericError, xmlGenericErrorContext);
va_start(ap, msg);
xmlVFormatLegacyError(ctx, "error", msg, ap);
va_end(ap);
}
/**
@ -813,9 +856,11 @@ xmlParserError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
void
xmlParserWarning(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
{
xmlParserCtxtPtr ctxt = ctx;
va_list ap;
xmlFormatError(&ctxt->lastError, xmlGenericError, xmlGenericErrorContext);
va_start(ap, msg);
xmlVFormatLegacyError(ctx, "warning", msg, ap);
va_end(ap);
}
/**
@ -830,9 +875,11 @@ xmlParserWarning(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
void
xmlParserValidityError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
{
xmlParserCtxtPtr ctxt = ctx;
va_list ap;
xmlFormatError(&ctxt->lastError, xmlGenericError, xmlGenericErrorContext);
va_start(ap, msg);
xmlVFormatLegacyError(ctx, "validity error", msg, ap);
va_end(ap);
}
/**
@ -847,9 +894,11 @@ xmlParserValidityError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
void
xmlParserValidityWarning(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
{
xmlParserCtxtPtr ctxt = ctx;
va_list ap;
xmlFormatError(&ctxt->lastError, xmlGenericError, xmlGenericErrorContext);
va_start(ap, msg);
xmlVFormatLegacyError(ctx, "validity warning", msg, ap);
va_end(ap);
}