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.
This commit is contained in:
Christoph M. Becker 2022-12-06 17:37:47 +01:00
parent a1a69c3734
commit aef7d810d3
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
2 changed files with 8 additions and 2 deletions

View file

@ -182,6 +182,7 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
php_struct *ctx = SG(server_context);
request_rec *r;
apr_bucket_brigade *brigade;
apr_status_t status;
r = ctx->r;
brigade = ctx->brigade;
@ -193,7 +194,7 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
* need to make sure that if data is available we fill the buffer completely.
*/
while (ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES, APR_BLOCK_READ, len) == APR_SUCCESS) {
while ((status = ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES, APR_BLOCK_READ, len)) == APR_SUCCESS) {
apr_brigade_flatten(brigade, buf, &len);
apr_brigade_cleanup(brigade);
tlen += len;
@ -204,6 +205,10 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
len = count_bytes - tlen;
}
if (status != APR_SUCCESS) {
return 0;
}
return tlen;
}