From ef56ddb6da3a2213a2cbb1754857c90f4291de7e Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Tue, 13 May 2003 16:01:04 +0000 Subject: [PATCH] merge this fix from 2.1-dev: Fix ap_construct_url() so that it surrounds IPv6 literal address strings with []. This fixes certain types of redirection. PR: 19207 Reviewed by: Bill Stoddard, Thom May git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/APACHE_2_0_BRANCH@99786 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 4 ++++ STATUS | 14 +------------- server/core.c | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CHANGES b/CHANGES index fd86e92b061..b9eb9cef455 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ Changes with Apache 2.0.46 + *) Fix ap_construct_url() so that it surrounds IPv6 literal address + strings with []. This fixes certain types of redirection. + PR 19207. [Jeff Trawick] + *) forward port of buffer overflow fixes for htdigest. [Thom May] *) Added AllowEncodedSlashes directive to permit control of whether diff --git a/STATUS b/STATUS index 82cde050c56..3cf28e077e8 100644 --- a/STATUS +++ b/STATUS @@ -1,5 +1,5 @@ APACHE 2.0 STATUS: -*-text-*- -Last modified at [$Date: 2003/05/13 15:51:04 $] +Last modified at [$Date: 2003/05/13 16:01:03 $] Release: @@ -217,18 +217,6 @@ PATCHES TO PORT FROM 2.1 modules/mappers/config9.m4 r1.16 +1: trawick, nd, stoddard - * Fix ap_construct_url() so that it surrounds IPv6 literal address - strings with []. This fixes certain types of redirection. - PR 19207. - server/core.c r1.232 - +1: nd - Oops! While r1.232 isn't actually broken functionally, it will - do an unnecessary string search with non-IPv6 builds because of a - bogus check for IPv6 capability. - server/core.c r1.232+r1.235 - +1: trawick, stoddard, thommay - - * Hook mod_rewrite's type checker before mod_mime's one. That way the RewriteRule [T=...] Flag should work as expected now. PR 19626. modules/mappers/mod_rewrite.c r1.150 diff --git a/server/core.c b/server/core.c index baee8f8325c..bc940dc18c3 100644 --- a/server/core.c +++ b/server/core.c @@ -893,6 +893,23 @@ AP_DECLARE(const char *) ap_get_server_name(request_rec *r) return r->server->server_hostname; } +/* + * Get the current server name from the request for the purposes + * of using in a URL. If the server name is an IPv6 literal + * address, it will be returned in URL format (e.g., "[fe80::1]"). + */ +static const char *get_server_name_for_url(request_rec *r) +{ + const char *plain_server_name = ap_get_server_name(r); + +#if APR_HAVE_IPV6 + if (ap_strchr_c(plain_server_name, ':')) { /* IPv6 literal? */ + return apr_psprintf(r->pool, "[%s]", plain_server_name); + } +#endif + return plain_server_name; +} + AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r) { apr_port_t port; @@ -933,7 +950,7 @@ AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r) { unsigned port = ap_get_server_port(r); - const char *host = ap_get_server_name(r); + const char *host = get_server_name_for_url(r); if (ap_is_default_port(port, r)) { return apr_pstrcat(p, ap_http_method(r), "://", host, uri, NULL); -- 2.47.3