Skip to content

Commit b669704

Browse files
committed
output: Fail starting to output buffer when the output layer is deactivated
Fixes #20837.
1 parent 03113b0 commit b669704

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

main/output.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,10 @@ PHPAPI zend_result php_output_handler_start(php_output_handler *handler)
538538
HashTable *rconflicts;
539539
php_output_handler_conflict_check_t conflict;
540540

541+
if (!(OG(flags) & PHP_OUTPUT_ACTIVATED)) {
542+
return FAILURE;
543+
}
544+
541545
if (php_output_lock_error(PHP_OUTPUT_HANDLER_START) || !handler) {
542546
return FAILURE;
543547
}

tests/output/gh20352.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ ob_start(new Test, 1);
2121
echo "trigger bug";
2222
?>
2323
--EXPECTF--
24+
%r(Notice: ob_start\(\): Failed to create buffer in [^\r\n]+ on line \d+\r?\n(\r?\n)?)+%r
25+
Notice: ob_start(): Failed to create buffer in %s on line %d
26+
2427
Fatal error: ob_start(): Cannot use output buffering in output buffering display handlers in %s on line %d

tests/output/gh20837.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
ob_start(): NULL dereference when calling ob_start() in shutdown function triggered by bailout in php_output_lock_error()
3+
--FILE--
4+
<?php
5+
6+
register_shutdown_function(function () {
7+
ob_start(function ($input) {
8+
echo "bar";
9+
return strtoupper($input);
10+
});
11+
});
12+
13+
ob_start(function () {
14+
ob_start();
15+
}, 1);
16+
17+
echo "foo";
18+
19+
?>
20+
--EXPECTF--
21+
Fatal error: ob_start(): Cannot use output buffering in output buffering display handlers in %s on line %d
22+
23+
Notice: ob_start(): Failed to create buffer in %s on line %d

0 commit comments

Comments
 (0)