[php-src] PR #25991: Fix GH-25644: Guard session encoding against re-entrancy
| From: | sanketpatel32 | Date: | Tue, 01 Dec 2026 06:41:03 +0000 |
| Subject: | [php-src] PR #25991: Fix GH-25644: Guard session encoding against re-entrancy | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-41305@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25991
Author: sanketpatel32
## Summary
Fixes #25644.
Session encoding can invoke userland
__serialize() methods. If those methods re-enter
session APIs which close or reinitialize the session, php_session_save_current_state()
can continue with a closed save handler and pass NULL module data to the files handler.
Track when session data is being encoded, reject re-entrant session state mutations with a warning,
and re-check that the session and save handler are still open after encoding before writing. The
encoded string is also released when the write is skipped.
Regression tests cover session_destroy(), session_abort(),
session_write_close(), session_reset(),
session_regenerate_id(), and session_decode() from
__serialize(). The session_destroy() case is covered with the
php, php_binary, and php_serialize serializers.
Tested with an --enable-debug --enable-address-sanitizer build:
```text
sapi/cli/php run-tests.php -P -q -j8 ext/session/tests
Number of tests : 275
Tests failed : 0
Tests passed : 274
Expected fail : 1
```