Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes-entries/substitute-maxlinelength-tail.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*) mod_substitute: Enforce SubstituteMaxLineLength on the unmatched tail
after substitutions. [Robert McConnell]
14 changes: 12 additions & 2 deletions modules/filters/mod_substitute.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,12 @@ static apr_status_t do_pattmatch(ap_filter_t *f, apr_bucket *inb,
/* XXX: we should check for AP_MAX_BUCKETS here and
* XXX: call ap_pass_brigade accordingly
*/
char *copy = ap_varbuf_pdup(pool, &vb, NULL, 0,
buff, bytes, &len);
char *copy;
if (vb.strlen > cfg->max_line_length
|| bytes > cfg->max_line_length - vb.strlen)
return APR_ENOMEM;
copy = ap_varbuf_pdup(pool, &vb, NULL, 0,
buff, bytes, &len);
ap_log_rerror(APLOG_MARK, APLOG_TRACE8, 0, f->r,
"New line (%" APR_SIZE_T_FMT " bytes): %.*s",
len, CAP2LINEMAX(len), copy);
Expand Down Expand Up @@ -389,6 +393,9 @@ static apr_status_t do_pattmatch(ap_filter_t *f, apr_bucket *inb,
/* Copy result plus the part after the last match into
* a bucket.
*/
if (vb.strlen > cfg->max_line_length
|| left > cfg->max_line_length - vb.strlen)
return APR_ENOMEM;
copy = ap_varbuf_pdup(pool, &vb, NULL, 0, pos, left,
&len);
ap_log_rerror(APLOG_MARK, APLOG_TRACE8, 0, f->r,
Expand All @@ -400,6 +407,9 @@ static apr_status_t do_pattmatch(ap_filter_t *f, apr_bucket *inb,
apr_bucket_delete(b);
b = tmp_b;
}
else if (have_match && left > space_left) {
return APR_ENOMEM;
}
}
else {
ap_assert(0);
Expand Down