]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
back-port this from 2.1-dev:
authorJeff Trawick <trawick@apache.org>
Wed, 26 May 2004 12:00:58 +0000 (12:00 +0000)
committerJeff Trawick <trawick@apache.org>
Wed, 26 May 2004 12:00:58 +0000 (12:00 +0000)
  Fix handling of IPv6 numeric strings in mod_proxy.

Submitted by: trawick
Reviewed by: minfrin, nd

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/APACHE_2_0_BRANCH@103774 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
modules/proxy/proxy_ftp.c
modules/proxy/proxy_http.c
modules/proxy/proxy_util.c

diff --git a/CHANGES b/CHANGES
index a803691852b883ad874722fad0de790faf76ae1a..107f1df503743cef78908edf7869066c6eca2b7b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,7 @@
 Changes with Apache 2.0.50
 
+  *) Fix handling of IPv6 numeric strings in mod_proxy.  [Jeff Trawick]
+
   *) mod_isapi: send_response_header() failed to copy status string's 
      last character.  PR 20619.  [Jesse Pelton <jsp pkc.com>]
 
diff --git a/STATUS b/STATUS
index 4b9b0e482364815ad7b2f34e1c3a32e5f5d8f55f..b55796d2c3d6068597f536abf5cd02a0e0ec715a 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -1,5 +1,5 @@
 APACHE 2.0 STATUS:                                              -*-text-*-
-Last modified at [$Date: 2004/05/26 11:50:42 $]
+Last modified at [$Date: 2004/05/26 12:00:57 $]
 
 Release:
 
@@ -83,12 +83,6 @@ PATCHES TO BACKPORT FROM 2.1
        PR 24922 [Pascal Terjan <pterjan@linuxfr.org>]
        +1: minfrin, nd
 
-    *) Fix handling of IPv6 numeric strings in mod_proxy.
-         modules/proxy/proxy_ftp.c r1.141, r1.142
-         modules/proxy/proxy_http.c r1.186
-         modules/proxy/proxy_util.c r1.107
-       +1: trawick, minfrin, nd
-
     *) RPM spec file changes: changed default dependancy to link to db4
        instead of db3. Fixed complaints about unpackaged files.
        build/rpm/httpd.spec.in: r1.5
index 8baba07d85a3bfa549105004934ca90885ce01a6..11c65c138ffe2fde4076abd547136ceeda5e2b28 100644 (file)
@@ -205,6 +205,9 @@ int ap_proxy_ftp_canon(request_rec *r, char *url)
     else
         sport[0] = '\0';
 
+    if (ap_strchr_c(host, ':')) { /* if literal IPv6 address */
+        host = apr_pstrcat(p, "[", host, "]", NULL);
+    }
     r->filename = apr_pstrcat(p, "proxy:ftp://", (user != NULL) ? user : "",
                               (password != NULL) ? ":" : "",
                               (password != NULL) ? password : "",
index 3c878b1b80c4877b08e1c26901b97a3d8110e913..630b0148f912bf0a48bab3e52cf5fcb2bf8fa942 100644 (file)
@@ -71,8 +71,12 @@ int ap_proxy_http_canon(request_rec *r, char *url)
      */
     port = def_port;
     err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
-    if (err)
+    if (err) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                      "error parsing URL %s: %s",
+                      url, err);
         return HTTP_BAD_REQUEST;
+    }
 
     /* now parse path/search args, according to rfc1738 */
     /* N.B. if this isn't a true proxy request, then the URL _path_
@@ -97,6 +101,9 @@ int ap_proxy_http_canon(request_rec *r, char *url)
     else
         sport[0] = '\0';
 
+    if (ap_strchr_c(host, ':')) { /* if literal IPv6 address */
+        host = apr_pstrcat(r->pool, "[", host, "]", NULL);
+    }
     r->filename = apr_pstrcat(r->pool, "proxy:", scheme, "://", host, sport, 
             "/", path, (search) ? "?" : "", (search) ? search : "", NULL);
     return OK;
index c876978bb37a8b5b11a75849a7cd03aae8594e83..036476026b4dfd683a1c92eeed0397f4ca6c15a5 100644 (file)
@@ -197,9 +197,10 @@ PROXY_DECLARE(char *)
      ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
                        char **passwordp, char **hostp, apr_port_t *port)
 {
-    int i;
-    char *strp, *host, *url = *urlp;
+    char *addr, *scope_id, *strp, *host, *url = *urlp;
     char *user = NULL, *password = NULL;
+    apr_port_t tmp_port;
+    apr_status_t rv;
 
     if (url[0] != '/' || url[1] != '/')
        return "Malformed URL";
@@ -238,44 +239,21 @@ PROXY_DECLARE(char *)
        *passwordp = password;
     }
 
-    strp = strrchr(host, ':');
-    if (strp != NULL) {
-       *(strp++) = '\0';
-
-       for (i = 0; strp[i] != '\0'; i++)
-           if (!apr_isdigit(strp[i]))
-               break;
-
-       /* if (i == 0) the no port was given; keep default */
-       if (strp[i] != '\0') {
-           return "Bad port number in URL";
-       } else if (i > 0) {
-            int int_port = atoi(strp);
-
-           if (int_port > 65535)
-               return "Port number in URL > 65535";
-
-           *port = (apr_port_t)int_port;
-       }
+    /* Parse the host string to separate host portion from optional port.
+     * Perform range checking on port.
+     */
+    rv = apr_parse_addr_port(&addr, &scope_id, &tmp_port, host, p);
+    if (rv != APR_SUCCESS || addr == NULL || scope_id != NULL) {
+        return "Invalid host/port";
     }
-    ap_str_tolower(host);              /* DNS names are case-insensitive */
-    if (*host == '\0')
-       return "Missing host in URL";
-/* check hostname syntax */
-    for (i = 0; host[i] != '\0'; i++)
-       if (!apr_isdigit(host[i]) && host[i] != '.')
-           break;
-    /* must be an IP address */
-    if (host[i] == '\0' && (apr_inet_addr(host) == -1))
-    {
-       return "Bad IP address in URL";
+    if (tmp_port != 0) { /* only update caller's port if port was specified */
+        *port = tmp_port;
     }
 
-/*    if (strchr(host,'.') == NULL && domain != NULL)
-   host = pstrcat(p, host, domain, NULL);
- */
+    ap_str_tolower(addr); /* DNS names are case-insensitive */
+
     *urlp = url;
-    *hostp = host;
+    *hostp = addr;
 
     return NULL;
 }