1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-31 06:50:06 +03:00

save: Fix handling of catastrophic errors

Don't overwrite catastrophic errors xmlSaveErr.

Overwrite non-catastrophic errors in xmlOutputBufferClose.
This commit is contained in:
Nick Wellnhofer 2024-12-18 23:37:35 +01:00
parent 72f84dd739
commit 0dd910e82b
6 changed files with 33 additions and 29 deletions

24
error.c
View File

@ -20,6 +20,30 @@
#include "private/globals.h"
#include "private/string.h"
int
xmlIsCatastrophicError(int level, int code) {
int fatal = 0;
if (level != XML_ERR_FATAL)
return(0);
switch (code) {
case XML_ERR_NO_MEMORY:
/* case XML_ERR_RESOURCE_LIMIT: */
case XML_ERR_SYSTEM:
case XML_ERR_ARGUMENT:
case XML_ERR_INTERNAL_ERROR:
fatal = 1;
break;
default:
if ((code >= 1500) && (code <= 1599))
fatal = 1;
break;
}
return(fatal);
}
/************************************************************************
* *
* Error struct *

View File

@ -10,6 +10,9 @@
struct _xmlNode;
XML_HIDDEN int
xmlIsCatastrophicError(int level, int code);
XML_HIDDEN void
xmlRaiseMemoryError(xmlStructuredErrorFunc schannel, xmlGenericErrorFunc channel,
void *data, int domain, xmlError *error);

View File

@ -68,8 +68,6 @@ xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
XML_HIDDEN void
xmlCtxtErrIO(xmlParserCtxtPtr ctxt, int code, const char *uri);
XML_HIDDEN int
xmlIsCatastrophicError(int level, int code);
XML_HIDDEN int
xmlCtxtIsCatastrophicError(xmlParserCtxtPtr ctxt);
XML_HIDDEN void

View File

@ -256,30 +256,6 @@ xmlCtxtErrIO(xmlParserCtxtPtr ctxt, int code, const char *uri)
msg, str1, str2);
}
int
xmlIsCatastrophicError(int level, int code) {
int fatal = 0;
if (level != XML_ERR_FATAL)
return(0);
switch (code) {
case XML_ERR_NO_MEMORY:
/* case XML_ERR_RESOURCE_LIMIT: */
case XML_ERR_SYSTEM:
case XML_ERR_ARGUMENT:
case XML_ERR_INTERNAL_ERROR:
fatal = 1;
break;
default:
if ((code >= 1500) && (code <= 1599))
fatal = 1;
break;
}
return(fatal);
}
int
xmlCtxtIsCatastrophicError(xmlParserCtxtPtr ctxt) {
if (ctxt == NULL)

View File

@ -1341,7 +1341,8 @@ xmlOutputBufferClose(xmlOutputBufferPtr out)
if (out->closecallback != NULL) {
int code = out->closecallback(out->context);
if ((code != XML_ERR_OK) && (out->error == XML_ERR_OK)) {
if ((code != XML_ERR_OK) &&
(!xmlIsCatastrophicError(XML_ERR_FATAL, out->error))) {
if (code < 0)
out->error = XML_IO_UNKNOWN;
else

View File

@ -83,8 +83,10 @@ xmlSaveErr(xmlOutputBufferPtr out, int code, xmlNodePtr node,
const char *msg = NULL;
int res;
/* Don't overwrite memory errors */
if ((out != NULL) && (out->error == XML_ERR_NO_MEMORY))
/* Don't overwrite catastrophic errors */
if ((out != NULL) &&
(out->error != XML_ERR_OK) &&
(xmlIsCatastrophicError(XML_ERR_FATAL, out->error)))
return;
if (code == XML_ERR_NO_MEMORY) {