summaryrefslogtreecommitdiff
path: root/nanohttp.c
diff options
context:
space:
mode:
authorSteve Wolf <stevewolf6@gmail.com>2013-02-28 18:22:46 +0800
committerDaniel Veillard <veillard@redhat.com>2013-02-28 18:22:46 +0800
commit19d785b5c76fcd9d7bc2c8d678b05ed83b02f91d (patch)
treee9b1904ee1a2315d1faf0e5e2ba4dac017d2f2dc /nanohttp.c
parentd749528aa9a5cfcddd6d021e346254c8727f194a (diff)
downloadlibxml2-19d785b5c76fcd9d7bc2c8d678b05ed83b02f91d.tar.gz
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.
Diffstat (limited to 'nanohttp.c')
-rw-r--r--nanohttp.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/nanohttp.c b/nanohttp.c
index c3f419f1..ac47ea67 100644
--- a/nanohttp.c
+++ b/nanohttp.c
@@ -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