Skip to content

Commit 887e6b9

Browse files
committed
Fix GH-15181: Disabled output handler is flushed again
When an `PHP_OUTPUT_HANDLER_FAILURE` occurs, the output handler becomes disabled (i.e. the `PHP_OUTPUT_HANDLER_DISABLED` flag is set). However, there is no guard for disabled handlers in `php_output_handler_op()` what may cause serious issues (as reported, UB due to passing `NULL` as the 2nd argument of `memcpy`, because the handler's buffer has already been `NULL`ed). Therefore, we add a respective guard for disabled handlers, and return `PHP_OUTPUT_HANDLER_FAILURE` right away. Closes GH-15183.
1 parent bc8909a commit 887e6b9

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PHP NEWS
88
. Fixed bug GH-15240 (Infinite recursion in trait hook). (ilutov)
99
. Fixed bug GH-15140 (Missing variance check for abstract set with asymmetric
1010
type). (ilutov)
11+
. Fixed bug GH-15181 (Disabled output handler is flushed again). (cmb)
1112

1213
- Date:
1314
. Constants SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING, and SUNFUNCS_RET_DOUBLE

main/output.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,10 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl
925925
);
926926
#endif
927927

928+
if (handler->flags & PHP_OUTPUT_HANDLER_DISABLED) {
929+
return PHP_OUTPUT_HANDLER_FAILURE;
930+
}
931+
928932
if (php_output_lock_error(context->op)) {
929933
/* fatal error */
930934
return PHP_OUTPUT_HANDLER_FAILURE;

tests/output/gh15181.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Fix GH-15181 (Disabled output handler is flushed again)
3+
--FILE--
4+
<?php
5+
ob_start(function () {
6+
throw new Exception('ob_start');
7+
});
8+
try {
9+
ob_flush();
10+
} catch (Throwable) {}
11+
ob_flush();
12+
?>
13+
===DONE===
14+
--EXPECT--
15+
===DONE===

0 commit comments

Comments
 (0)