From: André Malo Date: Mon, 12 Jan 2004 14:36:17 +0000 (+0000) Subject: fix double slash problem X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1326ae335f4cef70265a46ecb070ce489a4dbd04;p=thirdparty%2Fapache%2Fhttpd.git fix double slash problem Reviewed by: Jeff Trawick, Justin Erenkrantz git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@102286 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/CHANGES b/src/CHANGES index 01c5a594fcf..8cd63587fbe 100644 --- a/src/CHANGES +++ b/src/CHANGES @@ -1,5 +1,7 @@ Changes with Apache 1.3.30 + *) Fix RewriteBase directive to not add double slashes. [André Malo] + *) mod_rewrite: In external rewrite maps lookup keys containing a newline now cause a lookup failure. PR 14453. [Cedric Gavage , André Malo] diff --git a/src/modules/standard/mod_rewrite.c b/src/modules/standard/mod_rewrite.c index 98996a6eab8..1eb77bb6cef 100644 --- a/src/modules/standard/mod_rewrite.c +++ b/src/modules/standard/mod_rewrite.c @@ -4122,47 +4122,49 @@ static cacheentry *retrieve_cache_string(cache *c, char *res, char *key) ** +-------------------------------------------------------+ */ +/* + * substitute the prefix path 'match' in 'input' with 'subst' + * (think of RewriteBase which substitutes the physical path with + * the virtual path) + */ + static char *subst_prefix_path(request_rec *r, char *input, char *match, - char *subst) + const char *subst) { - char matchbuf[LONG_STRING_LEN]; - char substbuf[LONG_STRING_LEN]; - char *output; - int l; + size_t len = strlen(match); - output = input; - - /* first create a match string which always has a trailing slash */ - l = ap_cpystrn(matchbuf, match, sizeof(matchbuf) - 1) - matchbuf; - if (!l || matchbuf[l-1] != '/') { - matchbuf[l] = '/'; - matchbuf[l+1] = '\0'; - l++; - } - /* now compare the prefix */ - if (strncmp(input, matchbuf, l) == 0) { - rewritelog(r, 5, "strip matching prefix: %s -> %s", output, output+l); - output = ap_pstrdup(r->pool, output+l); - - /* and now add the base-URL as replacement prefix */ - l = ap_cpystrn(substbuf, subst, sizeof(substbuf) - 1) - substbuf; - if (!l || substbuf[l-1] != '/') { - substbuf[l] = '/'; - substbuf[l+1] = '\0'; - l++; - } - if (output[0] == '/') { - rewritelog(r, 4, "add subst prefix: %s -> %s%s", - output, substbuf, output+1); - output = ap_pstrcat(r->pool, substbuf, output+1, NULL); + if (len && match[len - 1] == '/') { + --len; + } + + if (!strncmp(input, match, len) && input[len++] == '/') { + size_t slen, outlen; + char *output; + + rewritelog(r, 5, "strip matching prefix: %s -> %s", input, input+len); + + slen = strlen(subst); + if (slen && subst[slen - 1] != '/') { + ++slen; } - else { - rewritelog(r, 4, "add subst prefix: %s -> %s%s", - output, substbuf, output); - output = ap_pstrcat(r->pool, substbuf, output, NULL); + + outlen = strlen(input) + slen - len; + output = ap_palloc(r->pool, outlen + 1); /* don't forget the \0 */ + + memcpy(output, subst, slen); + if (slen && !output[slen-1]) { + output[slen-1] = '/'; } + memcpy(output+slen, input+len, outlen - slen); + output[outlen] = '\0'; + + rewritelog(r, 4, "add subst prefix: %s -> %s", input+len, output); + + return output; } - return output; + + /* prefix didn't match */ + return input; } diff --git a/src/modules/standard/mod_rewrite.h b/src/modules/standard/mod_rewrite.h index 874efebd66c..d3f63aba59c 100644 --- a/src/modules/standard/mod_rewrite.h +++ b/src/modules/standard/mod_rewrite.h @@ -493,7 +493,7 @@ static void store_cache_string(cache *c, char *res, cacheentry *ce); /* misc functions */ static char *subst_prefix_path(request_rec *r, char *input, char *match, - char *subst); + const char *subst); static int parseargline(char *str, char **a1, char **a2, char **a3); static int prefix_stat(const char *path, ap_pool *pool); static void add_env_variable(request_rec *r, char *s);