httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@locus.apache.org
Subject cvs commit: httpd-2.0/server vhost.c
Date Sat, 16 Dec 2000 12:54:55 GMT
trawick     00/12/16 04:54:54

  Modified:    server   vhost.c
  Log:
  Use apr_parse_addr_port() in fix_hostname().  This simplifies the
  code by a small (okay, tiny) amount and lets IPv6 numeric address
  strings be passed through.
  Obtained from:  the idea is from the KAME IPv6 patch for Apache 1.3
  
  Revision  Changes    Path
  1.46      +31 -35    httpd-2.0/server/vhost.c
  
  Index: vhost.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/vhost.c,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- vhost.c	2000/12/16 11:36:16	1.45
  +++ vhost.c	2000/12/16 12:54:53	1.46
  @@ -713,45 +713,41 @@
    */
   static void fix_hostname(request_rec *r)
   {
  -    char *host = apr_palloc(r->pool, strlen(r->hostname) + 1);
  -    const char *src;
  +    char *host, *scope_id;
       char *dst;
  +    apr_port_t port;
  +    apr_status_t rv;
   
  -    /* check and copy the host part */
  -    src = r->hostname;
  -    dst = host;
  -    while (*src) {
  -	if (!apr_isalnum(*src) && *src != '-') {
  -	    if (*src == '.') {
  -		*dst++ = *src++;
  -		if (*src == '.')
  -		    goto bad;
  -		else
  -		    continue;
  -	    }
  -	    if (*src == ':')
  -		break;
  -	    else
  -		goto bad;
  -	} else {
  -	    *dst++ = *src++;
  -	}
  +    rv = apr_parse_addr_port(&host, &scope_id, &port, r->hostname, r->pool);
  +    if (rv != APR_SUCCESS || scope_id) {
  +        goto bad;
       }
  -    /* check the port part */
  -    if (*src++ == ':') {
  -	while (*src) {
  -	    if (!apr_isdigit(*src++)) {
  -		goto bad;
  -	    }
  -	}
  -    }
  -    /* strip trailing gubbins */
  -    if (dst > host && dst[-1] == '.') {
  -	dst[-1] = '\0';
  -    } else {
  -	dst[0] = '\0';
  -    }
   
  +    /* if the hostname is an IPv6 numeric address string, it was validated 
  +     * already; otherwise, further validation is needed 
  +     */
  +    if (r->hostname[0] != '[') {
  +        dst = host;
  +        while (*dst) {
  +            if (!apr_isalnum(*dst) && *dst != '-') {
  +                if (*dst == '.') {
  +                    dst++;
  +                    if (*dst == '.')
  +                        goto bad;
  +                    else
  +                        continue;
  +                }
  +                goto bad;
  +            }
  +            else {
  +                dst++;
  +            }
  +        }
  +        /* strip trailing gubbins */
  +        if (dst > host && dst[-1] == '.') {
  +            dst[-1] = '\0';
  +        }
  +    }
       r->hostname = host;
       return;
   
  
  
  

Mime
View raw message