joes 2004/06/25 18:36:24
Modified: src apreq_parsers.c
t parsers.c
. CHANGES
Log:
mfd parser fails to parse CRLF-terminated files when the terminating
boundary string is at the start of a new bucket. This is reportedly
a common event for PDF files uploaded with Netscape 7.
Submitted by: Jean-Fran�ois Meesse (Message-ID: <[EMAIL PROTECTED]>)
Reviewed by: joes
Revision Changes Path
1.50 +13 -3 httpd-apreq-2/src/apreq_parsers.c
Index: apreq_parsers.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/src/apreq_parsers.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- apreq_parsers.c 21 Jun 2004 17:49:18 -0000 1.49
+++ apreq_parsers.c 26 Jun 2004 01:36:24 -0000 1.50
@@ -668,6 +668,7 @@
continue;
}
+ look_for_boundary_up_front:
if (strncmp(bdry + off, buf, MIN(len, blen - off)) == 0) {
if ( len >= blen - off ) {
/* complete match */
@@ -688,13 +689,17 @@
continue;
}
else if (off > 0) {
- /* prior (partial) strncmp failed, restart */
+ /* prior (partial) strncmp failed,
+ * so we can move previous buckets across
+ * and retest buf against the full bdry.
+ */
do {
apr_bucket *f = APR_BRIGADE_FIRST(in);
APR_BUCKET_REMOVE(f);
APR_BRIGADE_INSERT_TAIL(out, f);
} while (e != APR_BRIGADE_FIRST(in));
off = 0;
+ goto look_for_boundary_up_front;
}
if (pattern != NULL && len >= blen) {
@@ -711,7 +716,12 @@
else
idx = apreq_index(buf, len, bdry, blen, APREQ_MATCH_PARTIAL);
- if (idx > 0)
+ /* Theoretically idx should never be 0 here, because we
+ * already tested the front of the brigade for a potential match.
+ * However, it doesn't hurt to allow for the possibility,
+ * since this will just start the whole loop over again.
+ */
+ if (idx >= 0)
apr_bucket_split(e, idx);
APR_BUCKET_REMOVE(e);
@@ -1071,7 +1081,7 @@
param->bb, ctx->bb);
if (param->v.status != APR_SUCCESS)
- return s;
+ return param->v.status;
ctx->status = MFD_NEXTLINE;
goto mfd_parse_brigade;
1.15 +3 -3 httpd-apreq-2/t/parsers.c
Index: parsers.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/t/parsers.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- parsers.c 19 Jun 2004 20:03:59 -0000 1.14
+++ parsers.c 26 Jun 2004 01:36:24 -0000 1.15
@@ -32,7 +32,7 @@
"--AaB03x" CRLF
"content-disposition: form-data; name=\"pics\"; filename=\"file1.txt\"" CRLF
"Content-Type: text/plain" CRLF CRLF
-"... contents of file1.txt ..." CRLF
+"... contents of file1.txt ..." CRLF CRLF
"--AaB03x--" CRLF;
extern apr_bucket_brigade *bb;
@@ -120,8 +120,8 @@
t = apreq_value_to_param(apreq_strtoval(val))->info;
bb = apreq_value_to_param(apreq_strtoval(val))->bb;
apr_brigade_pflatten(bb, (char **)&val, &len, p);
- CuAssertIntEquals(tc,strlen("... contents of file1.txt ..."), len);
- CuAssertStrNEquals(tc,"... contents of file1.txt ...", val, len);
+ CuAssertIntEquals(tc,strlen("... contents of file1.txt ..." CRLF),
len);
+ CuAssertStrNEquals(tc,"... contents of file1.txt ..." CRLF, val,
len);
val = apr_table_get(t, "content-type");
CuAssertStrEquals(tc, "text/plain", val);
}
1.44 +5 -0 httpd-apreq-2/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/httpd-apreq-2/CHANGES,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- CHANGES 23 Jun 2004 02:22:28 -0000 1.43
+++ CHANGES 26 Jun 2004 01:36:24 -0000 1.44
@@ -3,6 +3,11 @@
@section v2_04_dev Changes with libapreq2-2.04-dev
+- C API [Jean-Fran�ois Meesse]
+ mfd parser fails to parse CRLF-terminated files when the terminating
+ boundary string is at the start of a new bucket. This is reportedly
+ a common event for PDF files uploaded with Netscape 7.
+
- Perl API [joes]
Add back-compat support for Apache::Cookie->fetch() via
Apache->request.