Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changes-entries/rewrite_expr_backref.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*) mod_rewrite: Fix a crash, or stray bytes in the substitution, when a
%N backreference follows a "RewriteCond expr" that matched without
capturing anything. %N now expands to an empty string there.
PR 70369 [Arturo Bernal]
2 changes: 1 addition & 1 deletion modules/mappers/mod_rewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -4280,7 +4280,7 @@ static cond_return_type apply_rewrite_cond(rewritecond_entry *p, rewrite_ctx *ct

case CONDPAT_AP_EXPR:
{
const char *err, *source;
const char *err, *source = NULL;
rc = ap_expr_exec_re(r, p->expr, AP_MAX_REG_MATCH, regmatch,
&source, &err);
if (rc < 0 || err) {
Expand Down
34 changes: 34 additions & 0 deletions test/modules/mappers/test_001_rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,37 @@ def test_rewrite_002_02_escape_directs(self, env):
r'.*:warn\].*', r'.*:trace\d\].*'])
assert found, \
"Log should show 'escaping ... for redirect' for tab in target"


class TestRewriteExprBackref:

@pytest.fixture(autouse=True, scope='class')
@classmethod
def _class_scope(cls, env):
conf = HttpdConf(env, extras={
f"test1.{env.http_tld}": """
RewriteEngine On
RewriteCond %{HTTP:X-Data} ^(.+)$
RewriteRule ^/exprref-prime/ - [E=PRIME:%1]
RewriteCond %{HTTP_HOST} ^(.+)$
RewriteCond expr "'a' == 'a'"
RewriteRule ^/exprref/(.*)$ /target/[%1] [R=302,L]
""",
})
conf.add_vhost_test1()
conf.install()
assert env.apache_restart() == 0

# %1 after a "RewriteCond expr" that captured nothing expands to an
# empty string (BZ 70369)
def test_rewrite_003_01_expr_cond_no_capture(self, env):
prime = env.mkurl("http", "test1", "/exprref-prime/")
url = env.mkurl("http", "test1", "/exprref/abc")
for _ in range(10):
# leave stack data from an earlier request behind
env.curl_raw(prime, options=["-H", f"X-Data: {'Z' * 80}"])
r = env.curl_raw(url, options=["--max-redirs", "0"])
assert r.exit_code == 0, f"{r}"
assert r.response["status"] == 302
loc = r.response["header"]["location"]
assert loc.endswith("/target/%5b%5d"), f"Location: {loc}"
Loading