@@ -156,6 +156,20 @@ static void make_cookie(request_rec *r)
156156 * which has three subexpressions, $0..$2 */
157157#define NUM_SUBS 3
158158
159+ static void set_and_comp_regexp (cookie_dir_rec * dcfg ,
160+ apr_pool_t * p ,
161+ const char * cookie_name )
162+ {
163+ /* The goal is to end up with this regexp,
164+ * ^cookie_name=([^;]+)|;[\t]+cookie_name=([^;]+)
165+ * with cookie_name obviously substituted either
166+ * 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 );
169+
170+ dcfg -> regexp = ap_pregcomp (p , dcfg -> regexp_string , REG_EXTENDED );
171+ }
172+
159173static int spot_cookie (request_rec * r )
160174{
161175 cookie_dir_rec * dcfg = ap_get_module_config (r -> per_dir_config ,
@@ -214,6 +228,11 @@ static void *make_cookie_dir(apr_pool_t *p, char *d)
214228 dcfg -> cookie_domain = NULL ;
215229 dcfg -> style = CT_UNSET ;
216230 dcfg -> enabled = 0 ;
231+
232+ /* In case the user does not use the CookieName directive,
233+ * we need to compile the regexp for the default cookie name. */
234+ set_and_comp_regexp (dcfg , p , COOKIE_NAME );
235+
217236 return dcfg ;
218237}
219238
@@ -299,18 +318,10 @@ static const char *set_cookie_name(cmd_parms *cmd, void *mconfig,
299318{
300319 cookie_dir_rec * dcfg = (cookie_dir_rec * ) mconfig ;
301320
302- /* The goal is to end up with this regexp,
303- * ^cookie_name=([^;]+)|;[ \t]+cookie_name=([^;]+)
304- * with cookie_name
305- * obviously substituted with the real cookie name set by the
306- * user in httpd.conf. */
307- dcfg -> regexp_string = apr_pstrcat (cmd -> pool , "^" , name ,
308- "=([^;]+)|;[ \t]+" , name ,
309- "=([^;]+)" , NULL );
310-
311321 dcfg -> cookie_name = apr_pstrdup (cmd -> pool , name );
312322
313- dcfg -> regexp = ap_pregcomp (cmd -> pool , dcfg -> regexp_string , REG_EXTENDED );
323+ set_and_comp_regexp (dcfg , cmd -> pool , name );
324+
314325 if (dcfg -> regexp == NULL ) {
315326 return "Regular expression could not be compiled." ;
316327 }
0 commit comments