Skip to content

ext/session: Fix NULL pointer dereference in SessionHandler::create_sid() - #22580

Open
jorgsowa wants to merge 1 commit into
php:PHP-8.4from
jorgsowa:fix/session-handler-create-sid-null-deref
Open

ext/session: Fix NULL pointer dereference in SessionHandler::create_sid()#22580
jorgsowa wants to merge 1 commit into
php:PHP-8.4from
jorgsowa:fix/session-handler-create-sid-null-deref

Conversation

@jorgsowa

@jorgsowa jorgsowa commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

s_create_sid() can return NULL when php_random_bytes_throw() fails (e.g. CSPRNG exhaustion). Every other internal caller of s_create_sid() in session.c (php_session_initialize, session_regenerate_id) already NULL-checks the result.

It's not possible to test it through .phpt test file. Should it be pointed to the PHP8.4 branch?

@jorgsowa
jorgsowa requested a review from Girgias as a code owner July 3, 2026 17:31
@jorgsowa jorgsowa changed the title Fix NULL pointer dereference in SessionHandler::create_sid() ext/session: Fix NULL pointer dereference in SessionHandler::create_sid() Jul 3, 2026
@jorgsowa

Copy link
Copy Markdown
Contributor Author

Would you like to check this PR @iliaal ?

@iliaal

iliaal commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Looks right, might be worth retarget to 8.4 branch, since the issue is there too.

This and #22924 cover the last two of the six s_create_sid() call sites; the other four already check.

s_create_sid() can return NULL when php_random_bytes_throw() fails
(e.g. CSPRNG exhaustion), but RETURN_STR() dereferences the string
unconditionally. Every other internal caller of s_create_sid() in
session.c (php_session_initialize, session_regenerate_id) already
NULL-checks the result; this PHP-facing method, reachable from any
userland SessionHandler subclass via create_sid(), did not.

No dedicated regression test is added: forcing php_random_bytes_throw()
to fail is not portably reproducible from a .phpt test (it's a raw
getrandom() syscall on Linux and CCRandomGenerateBytes on macOS, neither
of which can be faulted from userland), which is also why the existing
NULL-checks this mirrors in session.c have none either.
@jorgsowa
jorgsowa force-pushed the fix/session-handler-create-sid-null-deref branch from bbee2d7 to 304f37e Compare July 31, 2026 14:38
@jorgsowa
jorgsowa changed the base branch from master to PHP-8.4 July 31, 2026 14:38
@jorgsowa

Copy link
Copy Markdown
Contributor Author

Re-targeted to 8.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants