Skip to content

Commit bbee2d7

Browse files
committed
Fix NULL pointer dereference in SessionHandler::create_sid()
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.
1 parent 04b63f9 commit bbee2d7

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

ext/session/mod_user_class.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ PHP_METHOD(SessionHandler, create_sid)
149149
PS_SANITY_CHECK;
150150

151151
id = PS(default_mod)->s_create_sid(&PS(mod_data));
152+
if (!id) {
153+
if (!EG(exception)) {
154+
zend_throw_error(NULL, "Failed to create session ID: %s", PS(default_mod)->s_name);
155+
}
156+
RETURN_THROWS();
157+
}
152158

153159
RETURN_STR(id);
154160
}

0 commit comments

Comments
 (0)