From: Jeff Trawick Date: Sat, 18 Sep 2004 16:18:26 +0000 (+0000) Subject: mod_rewrite: Handle per-location rules when r->filename is unset. X-Git-Tag: 2.1.1~242 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e88f02adb7e43967d0d88894662a40581ae048f;p=apache mod_rewrite: Handle per-location rules when r->filename is unset. Previously this would segfault or simply not match as expected, depending on the platform. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@105198 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index bf7f22e3db..301fa57ec8 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,10 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) mod_rewrite: Handle per-location rules when r->filename is unset. + Previously this would segfault or simply not match as expected, + depending on the platform. [Jeff Trawick] + *) Unix MPMs: Shut down the server more quickly when child processes are slow to exit. [Joe Orton, Jeff Trawick] diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 58f9a78e49..066b0521a6 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -4479,9 +4479,17 @@ static int hook_fixup(request_rec *r) * remember the current filename before rewriting for later check * to prevent deadlooping because of internal redirects * on final URL/filename which can be equal to the inital one. + * also, we'll restore original r->filename if we decline this + * request */ ofilename = r->filename; + if (r->filename == NULL) { + r->filename = apr_pstrdup(r->pool, r->uri); + rewritelog((r, 2, "init rewrite engine with requested uri %s", + r->filename)); + } + /* * now apply the rules ... */ @@ -4627,7 +4635,7 @@ static int hook_fixup(request_rec *r) * use the following internal redirection stuff because * this would lead to a deadloop. */ - if (strcmp(r->filename, ofilename) == 0) { + if (ofilename != NULL && strcmp(r->filename, ofilename) == 0) { rewritelog((r, 1, dconf->directory, "initial URL equal rewritten" " URL: %s [IGNORING REWRITE]", r->filename)); return OK; @@ -4680,6 +4688,7 @@ static int hook_fixup(request_rec *r) } else { rewritelog((r, 1, dconf->directory, "pass through %s", r->filename)); + r->filename = ofilename; return DECLINED; } }