You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-cvs@httpd.apache.org by jo...@apache.org on 2004/07/18 05:54:20 UTC
cvs commit: httpd-apreq-2/t cookie.c
joes 2004/07/17 20:54:20
Modified: src apreq_cookie.c
t cookie.c
Log:
Upgrade get_pair in apreq_cookie.c to deal with common non-compliant cookies.
Revision Changes Path
1.27 +19 -8 httpd-apreq-2/src/apreq_cookie.c
Index: apreq_cookie.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_cookie.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- apreq_cookie.c 5 Jul 2004 17:39:50 -0000 1.26
+++ apreq_cookie.c 18 Jul 2004 03:54:20 -0000 1.27
@@ -187,20 +187,29 @@
const char *d = *data;
unsigned char in_quotes = 0;
+ while(apr_isspace(*d))
+ ++d;
+
*n = d;
- while (*d != '=' && !apr_isspace(*d)) {
- if (*d++ == 0) {
- /*error: no '=' sign detected */
- *data = d-1;
- return APR_EGENERAL;
- }
- }
+ while (apr_isalnum(*d))
+ ++d;
*nlen = d - *n;
+ while(apr_isspace(*d))
+ ++d;
+
+ if (*d != '=') {
+ *data = d;
+ *v = d;
+ *vlen = 0;
+ return APR_NOTFOUND;
+ }
+
+
do ++d;
- while (*d == '=' || apr_isspace(*d));
+ while (apr_isspace(*d));
*v = d;
@@ -350,6 +359,7 @@
return j;
}
+ ++hdr;
status = get_pair(&hdr, &name, &nlen, &value, &vlen);
if (status != APR_SUCCESS) {
j->status = status;
@@ -395,6 +405,7 @@
apreq_log(APREQ_WARN status, env,
"Skipping bad NAME=VALUE pair: %s",
apr_pstrmemdup(p, name, hdr-name));
+ c = NULL;
}
}
}
1.11 +9 -4 httpd-apreq-2/t/cookie.c
Index: cookie.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/t/cookie.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- cookie.c 17 Jul 2004 01:09:39 -0000 1.10
+++ cookie.c 18 Jul 2004 03:54:20 -0000 1.11
@@ -24,8 +24,8 @@
static void jar_make(CuTest *tc)
{
- j = apreq_jar(p,"a=1; foo=bar; fl=left; fr=right; frl=right-left; flr=left-right; fll=left-left; b=2");
-
+ j = apreq_jar(p,"a=1; foo=bar; fl=left; fr=right;bad; ns=foo=1&bar=2,"
+ "frl=right-left; flr=left-right; fll=left-left; bad");
CuAssertPtrNotNull(tc, j);
}
@@ -35,8 +35,13 @@
val = apr_table_get(j->cookies,"a");
CuAssertStrEquals(tc,"1",val);
- val = apr_table_get(j->cookies,"b");
- CuAssertStrEquals(tc,"2",val);
+
+ /* ignore wacky cookies that don't have an '=' sign */
+ val = apr_table_get(j->cookies,"bad");
+ CuAssertPtrEquals(tc,NULL,val);
+ /* accept wacky cookies that contain multiple '=' */
+ val = apr_table_get(j->cookies,"ns");
+ CuAssertStrEquals(tc,"foo=1&bar=2",val);
val = apr_table_get(j->cookies,"foo");
CuAssertStrEquals(tc,"bar",val);