Skip to content

Commit c91445b

Browse files
committed
*) mod_rewrite: Improve safe question mark detection
Trunk version of patch: https://svn.apache.org/r1920566 Backport version for 2.4.x of patch: Trunk version of patch works svn merge -c 1920566 ^/httpd/httpd/trunk . +1: rpluem, covener, jorton git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1920982 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5f82765 commit c91445b

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

modules/mappers/mod_rewrite.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,21 +2442,19 @@ static char *do_expand(char *input, rewrite_ctx *ctx, rewriterule_entry *entry,
24422442
*unsafe_qmark = 0;
24432443

24442444
/* keep tracking only if interested in the last qmark */
2445-
if (entry && (entry->flags & RULEFLAG_QSLAST)) {
2446-
do {
2447-
span++;
2448-
span += strcspn(input + span, EXPAND_SPECIALS "?");
2449-
} while (input[span] == '?');
2450-
}
2451-
else {
2445+
if (!entry || !(entry->flags & RULEFLAG_QSLAST)) {
24522446
unsafe_qmark = NULL;
2453-
span += strcspn(input + span, EXPAND_SPECIALS);
24542447
}
2448+
2449+
/* find the next real special char, any (last) qmark up to
2450+
* there is safe too
2451+
*/
2452+
span += strcspn(input + span, EXPAND_SPECIALS);
24552453
}
24562454
}
24572455

2458-
/* fast exit */
2459-
if (inputlen == span) {
2456+
/* fast path (no specials) */
2457+
if (span >= inputlen) {
24602458
return apr_pstrmemdup(pool, input, inputlen);
24612459
}
24622460

@@ -2637,16 +2635,14 @@ static char *do_expand(char *input, rewrite_ctx *ctx, rewriterule_entry *entry,
26372635
*unsafe_qmark = 0;
26382636

26392637
/* keep tracking only if interested in the last qmark */
2640-
if (entry && (entry->flags & RULEFLAG_QSLAST)) {
2641-
do {
2642-
span++;
2643-
span += strcspn(p + span, EXPAND_SPECIALS "?");
2644-
} while (p[span] == '?');
2645-
}
2646-
else {
2638+
if (!entry || !(entry->flags & RULEFLAG_QSLAST)) {
26472639
unsafe_qmark = NULL;
2648-
span += strcspn(p + span, EXPAND_SPECIALS);
26492640
}
2641+
2642+
/* find the next real special char, any (last) qmark up to
2643+
* there is safe too
2644+
*/
2645+
span += strcspn(p + span, EXPAND_SPECIALS);
26502646
}
26512647
}
26522648
if (span > 0) {

0 commit comments

Comments
 (0)