https://bz.apache.org/bugzilla/show_bug.cgi?id=70169
Bug ID: 70169
Summary: RewriteCond expr !(...) is true if ... fails
Product: Apache httpd-2
Version: 2.4.68
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P2
Component: mod_rewrite
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Assume the configuration
RewriteCond expr "!(...)"
and assume that the evaluation of "(...)" gives an error. I do not mean that
the evaluation of "(...)" returns false (0). I mean that running the expression
evaluation itself fails due to an error. So it returns -1 and sets ctx->err. In
this case the RewriteCond is true.
Note that if we wrote the semantically equivalent
RewriteCond expr "not(...)"
then the RewriteCond would be false if the evaluation of "(...)" returned an
error.
This is because of the following code in cmd_rewritecond:
/* arg2: the pattern */
newcond->pattern = a2;
if (*a2 == '!') {
newcond->flags |= CONDFLAG_NOTMATCH;
++a2;
}
/* determine the pattern type */
newcond->ptype = CONDPAT_REGEX;
if (strcasecmp(a1, "expr") == 0) {
newcond->ptype = CONDPAT_AP_EXPR;
}
So the presence of "!" is checked before checking for "expr". The "!" is
consumed and the parsed expression is "(...)" and not "!(...)". The evaluation
result is inverted in apply_rewrite_cond based on flags & CONDFLAG_NOTMATCH. So
if the evaluation raises an error it is equivalent to an expression evaluating
to false and flags & CONDFLAG_NOTMATCH inverts it to true.
This is not the case if we used "not(...)". Then the negation is part of the
expression to evaluate and flags & CONDFLAG_NOTMATCH is false. The failure
result is not inverted any more.
In my opinion the "!" should not be checked and consumed if the first argument
of RewriteCond is "expr".
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]