[php-src] master: Fix unchecked brigade flatten errors in apache2handler (#25176)
| From: | Josh via GitHub | Date: | Wed, 18 Nov 2026 01:49:35 +0000 |
| Subject: | [php-src] master: Fix unchecked brigade flatten errors in apache2handler (#25176) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143818@lists.php.net to get a copy of this message | ||
Author: Josh (joshtrichards)
Committer: GitHub (web-flow)
Pusher: iliaal
Date: 2026-11-17T20:49:32-05:00
Commit: https://github.com/php/php-src/commit/0f55811bca0bdc31b80ce24c810ebc5bd9819929
Raw diff: https://github.com/php/php-src/commit/0f55811bca0bdc31b80ce24c810ebc5bd9819929.diff
Fix unchecked brigade flatten errors in apache2handler (#25176)
php_apache_sapi_read_post() checks ap_get_brigade() errors but ignores the return value of
apr_brigade_flatten().
If a bucket read fails during flattening, APR returns before updating the supplied length. The
callback then counts the requested length as successfully read, potentially reporting bytes that
were not written into the destination buffer.
Apache's core input filter normally reads socket buckets and propagates errors through
ap_get_brigade(), so ordinary network failures are already handled. This change defensively handles
any bucket-read failure occurring during the subsequent flatten operation; no such failure has been
demonstrated with the standard input-filter chain.
Check the flatten result after cleaning up the brigade and return zero on failure, matching the
existing handling of ap_get_brigade() errors. Successful reads are unchanged.
Changed paths:
M sapi/apache2handler/sapi_apache2.c
Diff:
diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c
index 44c6b2ca1b3e..67585e84b78b 100644
--- a/sapi/apache2handler/sapi_apache2.c
+++ b/sapi/apache2handler/sapi_apache2.c
@@ -192,8 +192,13 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
*/
while ((status = ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES, APR_BLOCK_READ,
len)) == APR_SUCCESS) {
- apr_brigade_flatten(brigade, buf, &len);
+ status = apr_brigade_flatten(brigade, buf, &len);
apr_brigade_cleanup(brigade);
+
+ if (status != APR_SUCCESS) {
+ return 0;
+ }
+
tlen += len;
if (tlen == count_bytes || !len) {
break;