Skip to content

mod_setenvif: look up the header again after a SetEnvIfExpr rule (#860) - #1050

Open
arturobernalg wants to merge 1 commit into
apache:2.4.xfrom
arturobernalg:backport/pr860-setenvif-expr-24x
Open

arturobernalg wants to merge 1 commit into
apache:2.4.xfrom
arturobernalg:backport/pr860-setenvif-expr-24x

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

Backport of #860 (trunk 97e4791) to 2.4.x. Original author: @arshsmith1.

match_headers() reuses the looked-up value for consecutive SetEnvIf rules on the same header. A SetEnvIfExpr rule in between can repoint that value at the string its regex was applied to, so the next rule for the earlier header was matched against the wrong value (with the earlier header's length). The fix makes expression rules force a fresh header lookup.

The cherry-pick applies cleanly to 2.4.x; no changes to the code, test or changes entry.

Tested on a 2.4.x build with test/runtests.sh modules/metadata: the new test_005_setenvif fails with only mod_setenvif.c reverted (SEI_LITERAL and SEI_REGEX get set from X-B) and passes with the fix. The rest of the metadata suite stays green (22 passed, 66 skipped, 5 xfailed).


[x] This PR does not report or address a security vulnerability
(see SECURITY.md and
https://www.apache.org/security/#reporting-a-vulnerability).
[x] Code follows the httpd style guide.
[x] New log messages (level debug or higher) use an empty APLOGNO() tag;
numbers are assigned by a committer at merge time (see docs/log-message-tags/README). (No new log messages.)
[x] If the change is user-visible, a changes-entries/*.txt file is included,
following the template in README.CHANGES (not needed otherwise).
[x] Test cases based on pyhttpd are included where appropriate, in the
test/modules/xxx directory matching the modules/xxx module source,
or test/modules/core for core server changes. On Unix, verify these
pass locally with e.g. make check-pytest PYTEST_DIRS=test/modules/xxx.

…che#860)

match_headers() reuses val and val_len for consecutive rules on the
same header, but a SetEnvIfExpr rule in between can point val at the
string its regex was applied to.  The next rule for the earlier header
was then matched against that other value, with the earlier header's
length.  Reset last_name for expression rules so the value is looked
up again.

* modules/metadata/mod_setenvif.c (match_headers): Reset last_name
  for expression rules.

* test/modules/metadata/test_005_setenvif.py: New test.

(cherry picked from commit 97e4791)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants