Skip to content

Commit ca06e80

Browse files
author
Andre Malo
committed
escape the cookie_name before pasting into the regexp.
Reviewed by: Jeff Trawick, Justin Erenkrantz git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/APACHE_2_0_BRANCH@104693 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4e2eb43 commit ca06e80

3 files changed

Lines changed: 39 additions & 8 deletions

File tree

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Changes with Apache 2.0.51
22

3+
*) mod_usertrack: Escape the cookie name before pasting into the
4+
regexp. [Andr� Malo]
5+
36
*) Extend the SetEnvIf directive to capture subexpressions of the
47
matched value. [Andr� Malo]
58

STATUS

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
APACHE 2.0 STATUS: -*-text-*-
2-
Last modified at [$Date: 2004/08/17 16:44:14 $]
2+
Last modified at [$Date: 2004/08/17 19:56:34 $]
33

44
Release:
55

@@ -210,11 +210,6 @@ PATCHES TO BACKPORT FROM 2.1
210210
modules/loggers/mod_log_config.c: r1.116
211211
+1: nd
212212

213-
*) mod_usertrack: Escape the cookie_name before pasting into the regexp.
214-
(2.0 + 1.3)
215-
modules/metadata/mod_usertrack.c: r1.51
216-
+1: nd, trawick, jerenkrantz
217-
218213
*) Fix memory leak in mod_rewrite. PR 27862. (2.0 + 1.3)
219214
http://www.apache.org/~nd/mod_rewrite_fixleak.diff
220215
+1: nd

modules/metadata/mod_usertrack.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,45 @@ static void set_and_comp_regexp(cookie_dir_rec *dcfg,
160160
apr_pool_t *p,
161161
const char *cookie_name)
162162
{
163+
int danger_chars = 0;
164+
const char *sp = cookie_name;
165+
163166
/* The goal is to end up with this regexp,
164167
* ^cookie_name=([^;]+)|;[\t]+cookie_name=([^;]+)
165168
* with cookie_name obviously substituted either
166169
* with the real cookie name set by the user in httpd.conf, or with the
167-
* default COOKIE_NAME. */
168-
dcfg->regexp_string = apr_pstrcat(p, "^", cookie_name, "=([^;]+)|;[ \t]+", cookie_name, "=([^;]+)", NULL);
170+
* default COOKIE_NAME.
171+
*/
172+
173+
/* Anyway, we need to escape the cookie_name before pasting it
174+
* into the regex
175+
*/
176+
while (*sp) {
177+
if (!apr_isalnum(*sp)) {
178+
++danger_chars;
179+
}
180+
++sp;
181+
}
182+
183+
if (danger_chars) {
184+
char *cp;
185+
cp = apr_palloc(p, sp - cookie_name + danger_chars + 1); /* 1 == \0 */
186+
sp = cookie_name;
187+
cookie_name = cp;
188+
while (*sp) {
189+
if (!apr_isalnum(*sp)) {
190+
*cp++ = '\\';
191+
}
192+
*cp++ = *sp++;
193+
}
194+
*cp = '\0';
195+
}
196+
197+
dcfg->regexp_string = apr_pstrcat(p, "^",
198+
cookie_name,
199+
"=([^;]+)|;[ \t]+",
200+
cookie_name,
201+
"=([^;]+)", NULL);
169202

170203
dcfg->regexp = ap_pregcomp(p, dcfg->regexp_string, REG_EXTENDED);
171204
ap_assert(dcfg->regexp != NULL);

0 commit comments

Comments
 (0)