Commit 19d785b5 authored by Steve Wolf's avatar Steve Wolf Committed by Daniel Veillard

xmlCtxtReadFile doesn't work with literal IPv6 URLs

https://bugzilla.gnome.org/show_bug.cgi?id=694185

RedHat Bug 624626 discusses the new behavior of libxml regarding brackets
around IPv6 addresses.  In earlier versions such as 2.6.27, uri.c stripped the
brackets (e.g. uri->server == "fdf2:1e39:73d1:934e::119"); in the current
version it returns IPv6 addresses with brackets intact (e.g. uri->server
== "[fdf2:1e39:73d1:934e::119]").

Thus in 2.9.0, xmlCtxtReadFile() has a problem when it is passed a URL
containing a literal IPv6 address.  xmlCtxReadFile() and its subroutines pass
uri->server unchanged to getaddrinfo(), which doesn't recognize a bracketed
IPv6 address, so the read fails.

This strips the [ and ] from IPv6 addresses allowing getaddrinfo()
to work properly with such URIs.
parent d749528a
......@@ -276,6 +276,8 @@ xmlNanoHTTPCleanup(void) {
static void
xmlNanoHTTPScanURL(xmlNanoHTTPCtxtPtr ctxt, const char *URL) {
xmlURIPtr uri;
int len;
/*
* Clear any existing data from the context
*/
......@@ -307,7 +309,15 @@ xmlNanoHTTPScanURL(xmlNanoHTTPCtxtPtr ctxt, const char *URL) {
}
ctxt->protocol = xmlMemStrdup(uri->scheme);
ctxt->hostname = xmlMemStrdup(uri->server);
/* special case of IPv6 addresses, the [] need to be removed */
if ((uri->server != NULL) && (*uri->server == '[')) {
len = strlen(uri->server);
if ((len > 2) && (uri->server[len - 1] == ']')) {
ctxt->hostname = (char *) xmlCharStrndup(uri->server + 1, len -2);
} else
ctxt->hostname = xmlMemStrdup(uri->server);
} else
ctxt->hostname = xmlMemStrdup(uri->server);
if (uri->path != NULL)
ctxt->path = xmlMemStrdup(uri->path);
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment