apr_brigade_split_boundary: Rather than shaving one byte from
a bucket, ignore the byte instead on the next go-round.
@@ -395,6 +395,7 @@ APR_DECLARE(apr_status_t) apr_brigade_split_boundary(apr_bucket_brigade *bbOut,
apr_off_t maxbytes)
{
apr_off_t outbytes = 0;
+ apr_off_t ignore = 0;
if (!boundary || !boundary[0]) {
return APR_EINVAL;
@@ -447,12 +448,12 @@ APR_DECLARE(apr_status_t) apr_brigade_split_boundary(apr_bucket_brigade *bbOut,
* If we have at least one boundary worth of data, do an optimised
* substring search for the boundary, and split quickly if found.
*/
- if (len >= boundary_len) {
+ if ((len - ignore) >= boundary_len) {
apr_size_t off;
apr_size_t leftover;
- pos = strnstr(str, boundary, len);
+ pos = strnstr(str + ignore, boundary, len - ignore);
/* definitely found it, we leave */
if (pos != NULL) {
@@ -518,7 +519,9 @@ APR_DECLARE(apr_status_t) apr_brigade_split_boundary(apr_bucket_brigade *bbOut,
*/
else {
- apr_size_t off = 0;
+ apr_size_t off = ignore;
+
+ len -= ignore;
/* find all definite non matches */
while (len) {
@@ -644,11 +647,7 @@ skip:
*
* Bump one byte off, and loop round to search again.
*/
- apr_bucket_split(e, 1);
- APR_BUCKET_REMOVE(e);
- APR_BRIGADE_INSERT_TAIL(bbOut, e);
-
- outbytes++;
+ ignore++;
}
