[libxml2] xmlCtxtReadFile doesn't work with literal IPv6 URLs



commit 19d785b5c76fcd9d7bc2c8d678b05ed83b02f91d
Author: Steve Wolf <stevewolf6 gmail com>
Date:   Thu Feb 28 18:22:46 2013 +0800

    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.

 nanohttp.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/nanohttp.c b/nanohttp.c
index c3f419f..ac47ea6 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]