Skip to content

Commit 023b863

Browse files
allanrboFelipe Zimmerle
authored and
Felipe Zimmerle
committed
Ensure memory preallocation for streaming is bounded by SecRequestBodyLimit
1 parent 97b51eb commit 023b863

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

apache2/msc_reqbody.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ apr_status_t modsecurity_request_body_to_stream(modsec_rec *msr, const char *buf
434434
if (msr->stream_input_data == NULL) {
435435
// Is the request body length is known beforehand? (requests that are not Transfer-Encoding: chunked)
436436
if (msr->request_content_length > 0) {
437-
allocate_length = msr->request_content_length;
437+
// Use min of Content-Length and SecRequestBodyLimit
438+
allocate_length = min(msr->request_content_length, msr->txcfg->reqbody_limit);
438439
}
439440
else {
440441
// We don't know how this request is going to be, so hope for just buflen to begin with (requests that are Transfer-Encoding: chunked)
@@ -472,6 +473,9 @@ apr_status_t modsecurity_request_body_to_stream(modsec_rec *msr, const char *buf
472473
"Unable to reallocate memory to hold request body on stream. Asked for %" APR_SIZE_T_FMT " bytes.",
473474
allocate_length);
474475
free(msr->stream_input_data);
476+
msr->stream_input_data = NULL;
477+
msr->stream_input_length = 0;
478+
msr->stream_input_allocated_length = 0;
475479
return -1;
476480
}
477481
}

0 commit comments

Comments
 (0)