Skip to content

Commit e45a4d7

Browse files
committed
io: Always forward IO errors to global handler
The HTTP module raises errors without context. This won't be fixed, so send them to the global error handler.
1 parent a73483e commit e45a4d7

3 files changed

Lines changed: 29 additions & 16 deletions

File tree

parserInternals.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,22 +2122,14 @@ xmlNoNetExternalEntityLoader(const char *URL, const char *ID,
21222122
if (resource != NULL) {
21232123
if ((!xmlStrncasecmp(BAD_CAST resource, BAD_CAST "ftp://", 6)) ||
21242124
(!xmlStrncasecmp(BAD_CAST resource, BAD_CAST "http://", 7))) {
2125-
int res;
2126-
2125+
xmlCtxtErrIO(ctxt, XML_IO_NETWORK_ATTEMPT,
2126+
(const char *) resource);
21272127
/*
2128-
* Forward this error to the generic error handler, not to
2129-
* the parser context for backward compatibility.
2130-
* Several downstream test suites rely on this behavior.
2128+
* Also forward the error directly to the global error
2129+
* handler, which the XML::LibXML test suite expects.
21312130
*/
2132-
res = __xmlRaiseError(NULL, xmlGenericError,
2133-
xmlGenericErrorContext, NULL, NULL,
2134-
XML_FROM_IO, XML_IO_NETWORK_ATTEMPT,
2135-
XML_ERR_ERROR, NULL, 0,
2136-
(const char *) resource, NULL, NULL, 0, 0,
2137-
"Attempt to load network entity %s",
2138-
resource);
2139-
if (res < 0)
2140-
xmlCtxtErrMemory(ctxt);
2131+
__xmlIOErr(XML_FROM_IO, XML_IO_NETWORK_ATTEMPT,
2132+
(const char *) resource);
21412133
if (resource != (xmlChar *) URL)
21422134
xmlFree(resource);
21432135
return(NULL);

python/tests/input_callback.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def my_ctx_error_cb(arg, msg, severity, reserved):
9999
run_test(desc="Loading entity with custom callback",
100100
docpath=startURL, catalog=None,
101101
exp_status="loaded", exp_err=[
102+
( 3, 'failed to load "http://example.com/dtds/sample.dtd": Attempt to load network entity\n'),
102103
( -1, "Attempt to load network entity http://example.com/dtds/sample.dtd"),
103104
( 4, "Entity 'sample.entity' not defined\n")
104105
])

xmlIO.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ xmlIOErrMemory(void)
137137
int
138138
__xmlIOErr(int domain, int code, const char *extra)
139139
{
140+
xmlStructuredErrorFunc schannel = NULL;
141+
xmlGenericErrorFunc channel = NULL;
142+
void *data = NULL;
143+
const char *fmt, *arg;
140144
int res;
141145

142146
if (code == 0) {
@@ -297,10 +301,26 @@ __xmlIOErr(int domain, int code, const char *extra)
297301
else code = XML_IO_UNKNOWN;
298302
}
299303

300-
res = __xmlRaiseError(NULL, NULL, NULL, NULL, NULL,
304+
if (xmlStructuredError) {
305+
schannel = xmlStructuredError;
306+
data = xmlStructuredErrorContext;
307+
} else {
308+
channel = xmlGenericError;
309+
data = xmlGenericErrorContext;
310+
}
311+
312+
if (code == XML_IO_NETWORK_ATTEMPT) {
313+
fmt = "Attempt to load network entity %s";
314+
arg = extra;
315+
} else {
316+
fmt = "%s";
317+
arg = xmlErrString(code);
318+
}
319+
320+
res = __xmlRaiseError(schannel, channel, data, NULL, NULL,
301321
domain, code, XML_ERR_ERROR, NULL, 0,
302322
extra, NULL, NULL, 0, 0,
303-
"%s", xmlErrString(code));
323+
fmt, arg);
304324
if (res < 0) {
305325
xmlIOErrMemory();
306326
return(XML_ERR_NO_MEMORY);

0 commit comments

Comments
 (0)