Skip to content

Commit aef7d81

Browse files
committed
Fix GH-9949: Partial content on incomplete POST request
`ap_get_brigade()` may fail for different reasons, and we must not pretend that a partially read POST payload is fine; instead we report a content length of zero what matches all other `read_post()` callbacks of bundled SAPIs. Closes GH-10059.
1 parent a1a69c3 commit aef7d81

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

NEWS

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.1.15
44

5-
5+
- Apache:
6+
. Fixed bug GH-9949 (Partial content on incomplete POST request). (cmb)
67

78
05 Jan 2023, PHP 8.1.14
89

sapi/apache2handler/sapi_apache2.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
182182
php_struct *ctx = SG(server_context);
183183
request_rec *r;
184184
apr_bucket_brigade *brigade;
185+
apr_status_t status;
185186

186187
r = ctx->r;
187188
brigade = ctx->brigade;
@@ -193,7 +194,7 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
193194
* need to make sure that if data is available we fill the buffer completely.
194195
*/
195196

196-
while (ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES, APR_BLOCK_READ, len) == APR_SUCCESS) {
197+
while ((status = ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES, APR_BLOCK_READ, len)) == APR_SUCCESS) {
197198
apr_brigade_flatten(brigade, buf, &len);
198199
apr_brigade_cleanup(brigade);
199200
tlen += len;
@@ -204,6 +205,10 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
204205
len = count_bytes - tlen;
205206
}
206207

208+
if (status != APR_SUCCESS) {
209+
return 0;
210+
}
211+
207212
return tlen;
208213
}
209214

0 commit comments

Comments
 (0)