[php-src] master: Merge branch 'PHP-8.6'

From: Date: Wed, 23 Sep 2026 16:35:57 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141480@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-09-23T12:28:19-04:00 Commit: https://github.com/php/php-src/commit/84514fd63020c8614e1de8c03fa15177f731b86c Raw diff: https://github.com/php/php-src/commit/84514fd63020c8614e1de8c03fa15177f731b86c.diff Merge branch 'PHP-8.6' * PHP-8.6: ext/session: Preserve exceptions thrown by create_sid() Changed paths: A ext/session/tests/user_session_module/session_create_sid_return_destructor_throws.phpt A ext/session/tests/user_session_module/session_regenerate_id_create_sid_throws.phpt A ext/session/tests/user_session_module/session_start_create_sid_throws.phpt M ext/session/mod_user.c M ext/session/tests/user_session_module/session_create_id_create_sid_throws.phpt M ext/session/tests/user_session_module/session_start_strict_recreate_create_sid_fails.phpt Diff: diff --git a/ext/session/mod_user.c b/ext/session/mod_user.c index 5c6fe557771f..174a0e4822e2 100644 --- a/ext/session/mod_user.c +++ b/ext/session/mod_user.c @@ -234,7 +234,9 @@ PS_CREATE_SID_FUNC(user) if (UNEXPECTED(Z_TYPE(retval) != IS_STRING)) { /* Will no longer be needed in PHP 9 as the interface return type will be in effect */ - zend_throw_error(zend_ce_type_error, "Session id must be of type string, %s given", zend_zval_type_name(&retval)); + if (!EG(exception)) { + zend_throw_error(zend_ce_type_error, "Session id must be of type string, %s given", zend_zval_type_name(&retval)); + } zval_ptr_dtor(&retval); return NULL; } diff --git a/ext/session/tests/user_session_module/session_create_id_create_sid_throws.phpt b/ext/session/tests/user_session_module/session_create_id_create_sid_throws.phpt index c87df2ab458e..a8648fdb5d68 100644 --- a/ext/session/tests/user_session_module/session_create_id_create_sid_throws.phpt +++ b/ext/session/tests/user_session_module/session_create_id_create_sid_throws.phpt @@ -36,14 +36,13 @@ try { session_create_id(); } catch (Throwable $e) { echo $e::class, ": ", $e->getMessage(), PHP_EOL; - $previous = $e->getPrevious(); - echo $previous::class, ": ", $previous->getMessage(), PHP_EOL; + var_dump($e->getPrevious()); } var_dump(session_status() === PHP_SESSION_ACTIVE); ?> --EXPECT-- -TypeError: Session id must be of type string, null given Exception: create_sid failed +NULL bool(true) diff --git a/ext/session/tests/user_session_module/session_create_sid_return_destructor_throws.phpt b/ext/session/tests/user_session_module/session_create_sid_return_destructor_throws.phpt new file mode 100644 index 000000000000..7c8c9b1fdc71 --- /dev/null +++ b/ext/session/tests/user_session_module/session_create_sid_return_destructor_throws.phpt @@ -0,0 +1,38 @@ +--TEST-- +Exceptions from destruction of an invalid create_sid() return value are preserved +--EXTENSIONS-- +session +--FILE-- +<?php + +class FailingHandler implements SessionHandlerInterface, SessionIdInterface +{ + public function open($path, $name): bool { return true; } + public function close(): bool { return true; } + public function read($id): string|false { return ''; } + public function write($id, $data): bool { return true; } + public function destroy($id): bool { return true; } + public function gc($max_lifetime): int|false { return 0; } + public function validateId($id): bool { return true; } + + #[ReturnTypeWillChange] + public function create_sid() + { + return new class { + public function __destruct() + { + throw new RuntimeException('destructor failed'); + } + }; + } +} + +session_set_save_handler(new FailingHandler()); +try { + session_start(); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +?> +--EXPECT-- +RuntimeException: destructor failed diff --git a/ext/session/tests/user_session_module/session_regenerate_id_create_sid_throws.phpt b/ext/session/tests/user_session_module/session_regenerate_id_create_sid_throws.phpt new file mode 100644 index 000000000000..21e796ca13d0 --- /dev/null +++ b/ext/session/tests/user_session_module/session_regenerate_id_create_sid_throws.phpt @@ -0,0 +1,57 @@ +--TEST-- +session_regenerate_id() preserves exceptions from create_sid(), including collision retries +--EXTENSIONS-- +session +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.use_strict_mode=1 +session.gc_probability=0 +--FILE-- +<?php + +ob_start(); + +class FailingHandler implements SessionHandlerInterface, SessionIdInterface, SessionUpdateTimestampHandlerInterface +{ + public int $calls = 0; + public int $throwAt; + + public function open($path, $name): bool { return true; } + public function close(): bool { return true; } + public function read($id): string|false { return ''; } + public function write($id, $data): bool { return true; } + public function destroy($id): bool { return true; } + public function gc($max_lifetime): int|false { return 0; } + public function updateTimestamp($id, $data): bool { return true; } + public function validateId($id): bool { return true; } + + public function create_sid(): string + { + if (++$this->calls === $this->throwAt) { + throw new RuntimeException('create_sid failed'); + } + return 'session' . $this->calls; + } +} + +foreach ([2, 3] as $throwAt) { + $handler = new FailingHandler(); + $handler->throwAt = $throwAt; + session_set_save_handler($handler); + session_id(''); + session_start(); + + try { + session_regenerate_id(); + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; + } + echo 'create_sid calls: ', $handler->calls, PHP_EOL; +} +?> +--EXPECT-- +RuntimeException: create_sid failed +create_sid calls: 2 +RuntimeException: create_sid failed +create_sid calls: 3 diff --git a/ext/session/tests/user_session_module/session_start_create_sid_throws.phpt b/ext/session/tests/user_session_module/session_start_create_sid_throws.phpt new file mode 100644 index 000000000000..b7cd663007e0 --- /dev/null +++ b/ext/session/tests/user_session_module/session_start_create_sid_throws.phpt @@ -0,0 +1,64 @@ +--TEST-- +session_start() preserves exceptions from create_sid() +--EXTENSIONS-- +session +--INI-- +session.use_cookies=0 +session.cache_limiter= +session.gc_probability=0 +--FILE-- +<?php + +ob_start(); + +class FailingHandler implements SessionHandlerInterface, SessionIdInterface, SessionUpdateTimestampHandlerInterface +{ + public bool $invalidReturn = false; + + public function open($path, $name): bool { return true; } + public function close(): bool { return true; } + public function read($id): string|false { return ''; } + public function write($id, $data): bool { return true; } + public function destroy($id): bool { return true; } + public function gc($max_lifetime): int|false { return 0; } + public function updateTimestamp($id, $data): bool { return true; } + + public function create_sid(): string + { + if ($this->invalidReturn) { + return []; + } + throw new RuntimeException('create_sid failed'); + } + + public function validateId(string $id): bool + { + return false; + } +} + +$handler = new FailingHandler(); +session_set_save_handler($handler); + +foreach ([false, true] as $strict) { + foreach ([false, true] as $invalidReturn) { + echo 'strict mode: ', (int) $strict, ', invalid return: ', (int) $invalidReturn, PHP_EOL; + $handler->invalidReturn = $invalidReturn; + session_id($strict ? 'rejected' : ''); + try { + session_start(['use_strict_mode' => $strict]); + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; + } + } +} +?> +--EXPECT-- +strict mode: 0, invalid return: 0 +RuntimeException: create_sid failed +strict mode: 0, invalid return: 1 +TypeError: FailingHandler::create_sid(): Return value must be of type string, array returned +strict mode: 1, invalid return: 0 +RuntimeException: create_sid failed +strict mode: 1, invalid return: 1 +TypeError: FailingHandler::create_sid(): Return value must be of type string, array returned diff --git a/ext/session/tests/user_session_module/session_start_strict_recreate_create_sid_fails.phpt b/ext/session/tests/user_session_module/session_start_strict_recreate_create_sid_fails.phpt index 3e32c79641e3..0ddddaefdbb5 100644 --- a/ext/session/tests/user_session_module/session_start_strict_recreate_create_sid_fails.phpt +++ b/ext/session/tests/user_session_module/session_start_strict_recreate_create_sid_fails.phpt @@ -44,6 +44,6 @@ var_dump(defined('SID')); ?> --EXPECT-- -TypeError: Session id must be of type string, null given +RuntimeException: create_sid failed bool(false) bool(false)

« previous php.cvs (#141480) next »