Skip to content

Fix GH-15496: Fix accessing NULL pointer on output handler stack #19446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions ext/standard/tests/gh15496_original_reproducer.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--TEST--
GH-15496: Session handler ob_start crash
--FILE--
<?php
class MySessionHandler implements SessionHandlerInterface
{
public function open ($save_path, $session_name): bool
{
return true;
}

public function close(): bool
{
return true;
}

public function read($id): string
{
return '';
}

public function write($id, $sess_data): bool
{
ob_start(function () {});

return true;
}

public function destroy($id): bool
{
return true;
}

public function gc($maxlifetime): int
{
return 0;
}
}

session_set_save_handler(new MySessionHandler());
session_start();

ob_start(function() {
var_dump($b);
});

while (1) {
$a[] = 1;
}
?>
--EXPECTF--
Fatal error: {closure%A}(): Cannot use output buffering in output buffering display handlers in %s on line %d

Notice: ob_start(): Failed to create buffer in %s on line %d
3 changes: 3 additions & 0 deletions main/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,9 @@ PHPAPI int php_output_handler_start(php_output_handler *handler)
if (php_output_lock_error(PHP_OUTPUT_HANDLER_START) || !handler) {
return FAILURE;
}
if (!(OG(flags) & PHP_OUTPUT_ACTIVATED)) {
return FAILURE;
}
if (NULL != (conflict = zend_hash_find_ptr(&php_output_handler_conflicts, handler->name))) {
if (SUCCESS != conflict(ZSTR_VAL(handler->name), ZSTR_LEN(handler->name))) {
return FAILURE;
Expand Down
Loading