Skip to content

Commit 9c46db8

Browse files
akolganovchewi
authored andcommitted
Fix issues with uploading files over 8K : owasp-modsecurity#142, owasp-modsecurity#582 and owasp-modsecurity#830
1 parent b4ef9e5 commit 9c46db8

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

apache2/apache2_io.c

+24-25
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,16 @@ apr_status_t input_filter(ap_filter_t *f, apr_bucket_brigade *bb_out,
7777
}
7878
}
7979

80-
rc = modsecurity_request_body_retrieve(msr, &chunk, (unsigned int)nbytes, &my_error_msg);
81-
if (rc == -1) {
80+
do{
81+
rc = modsecurity_request_body_retrieve(msr, &chunk, (unsigned int)nbytes, &my_error_msg);
82+
if (rc == -1) {
8283
if (my_error_msg != NULL) {
8384
msr_log(msr, 1, "%s", my_error_msg);
8485
}
8586
return APR_EGENERAL;
86-
}
87+
}
8788

88-
if (chunk && (!msr->txcfg->stream_inbody_inspection || (msr->txcfg->stream_inbody_inspection && msr->if_stream_changed == 0))) {
89+
if (chunk && (!msr->txcfg->stream_inbody_inspection || (msr->txcfg->stream_inbody_inspection && msr->if_stream_changed == 0))) {
8990
/* Copy the data we received in the chunk */
9091
bucket = apr_bucket_heap_create(chunk->data, chunk->length, NULL,
9192
f->r->connection->bucket_alloc);
@@ -113,7 +114,7 @@ apr_status_t input_filter(ap_filter_t *f, apr_bucket_brigade *bb_out,
113114
if (msr->txcfg->debuglog_level >= 4) {
114115
msr_log(msr, 4, "Input filter: Forwarded %" APR_SIZE_T_FMT " bytes.", chunk->length);
115116
}
116-
} else if (msr->stream_input_data != NULL) {
117+
} else if (msr->stream_input_data != NULL) {
117118

118119
msr->if_stream_changed = 0;
119120

@@ -127,35 +128,33 @@ apr_status_t input_filter(ap_filter_t *f, apr_bucket_brigade *bb_out,
127128
}
128129
}
129130

130-
if (bucket == NULL) return APR_EGENERAL;
131-
APR_BRIGADE_INSERT_TAIL(bb_out, bucket);
132-
133-
if (msr->txcfg->debuglog_level >= 4) {
134-
msr_log(msr, 4, "Input stream filter: Forwarded %" APR_SIZE_T_FMT " bytes.", msr->stream_input_length);
135-
}
136-
137-
}
138-
139-
if (rc == 0) {
140-
modsecurity_request_body_retrieve_end(msr);
141-
142131
if (msr->if_seen_eos) {
143-
bucket = apr_bucket_eos_create(f->r->connection->bucket_alloc);
144132
if (bucket == NULL) return APR_EGENERAL;
145133
APR_BRIGADE_INSERT_TAIL(bb_out, bucket);
146134

147135
if (msr->txcfg->debuglog_level >= 4) {
148-
msr_log(msr, 4, "Input filter: Sent EOS.");
136+
msr_log(msr, 4, "Input stream filter: Forwarded %" APR_SIZE_T_FMT " bytes.", msr->stream_input_length);
149137
}
150138
}
139+
}
140+
} while (rc != 0);
151141

152-
/* We're done */
153-
msr->if_status = IF_STATUS_COMPLETE;
154-
ap_remove_input_filter(f);
142+
modsecurity_request_body_retrieve_end(msr);
155143

156-
if (msr->txcfg->debuglog_level >= 4) {
157-
msr_log(msr, 4, "Input filter: Input forwarding complete.");
158-
}
144+
bucket = apr_bucket_eos_create(f->r->connection->bucket_alloc);
145+
if (bucket == NULL) return APR_EGENERAL;
146+
APR_BRIGADE_INSERT_TAIL(bb_out, bucket);
147+
148+
if (msr->txcfg->debuglog_level >= 4) {
149+
msr_log(msr, 4, "Input filter: Sent EOS.");
150+
}
151+
152+
/* We're done */
153+
msr->if_status = IF_STATUS_COMPLETE;
154+
ap_remove_input_filter(f);
155+
156+
if (msr->txcfg->debuglog_level >= 4) {
157+
msr_log(msr, 4, "Input filter: Input forwarding complete.");
159158
}
160159

161160
return APR_SUCCESS;

0 commit comments

Comments
 (0)