Skip to content

Commit b510250

Browse files
committed
Fix #79413: session_create_id() fails for active sessions
The comment on `PS_VALIDATE_SID_FUNC(files)` is very clear that the function is supposed to return `SUCCESS` if the session already exists. So to detect a collision, we have to check for `SUCCESS`, not `FAILURE`. We also fix the wrong condition in session_regenerate_id() as well.
1 parent a681b12 commit b510250

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ PHP NEWS
2020
. Fixed bug #79412 (Opcache chokes and uses 100% CPU on specific script).
2121
(Dmitry)
2222

23+
- Session:
24+
. Fixed bug #79413 (session_create_id() fails for active sessions). (cmb)
25+
2326
- Shmop:
2427
. Fixed bug #79427 (Integer Overflow in shmop_open()). (cmb)
2528

ext/session/session.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,7 @@ static PHP_FUNCTION(session_regenerate_id)
22232223
RETURN_FALSE;
22242224
}
22252225
if (PS(use_strict_mode) && PS(mod)->s_validate_sid &&
2226-
PS(mod)->s_validate_sid(&PS(mod_data), PS(id)) == FAILURE) {
2226+
PS(mod)->s_validate_sid(&PS(mod_data), PS(id)) == SUCCESS) {
22272227
zend_string_release_ex(PS(id), 0);
22282228
PS(id) = PS(mod)->s_create_sid(&PS(mod_data));
22292229
if (!PS(id)) {
@@ -2285,7 +2285,7 @@ static PHP_FUNCTION(session_create_id)
22852285
break;
22862286
} else {
22872287
/* Detect collision and retry */
2288-
if (PS(mod)->s_validate_sid(&PS(mod_data), new_id) == FAILURE) {
2288+
if (PS(mod)->s_validate_sid(&PS(mod_data), new_id) == SUCCESS) {
22892289
zend_string_release_ex(new_id, 0);
22902290
new_id = NULL;
22912291
continue;

ext/session/tests/bug79091.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class MySessionHandler implements SessionHandlerInterface, SessionIdInterface, S
5050

5151
public function validateId($key)
5252
{
53-
return false;
53+
return true;
5454
}
5555
}
5656

ext/session/tests/bug79413.phpt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #79413 (session_create_id() fails for active sessions)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('session')) die('skip session extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
session_start();
10+
$old = session_id();
11+
$new = session_create_id();
12+
var_dump($new !== $old);
13+
?>
14+
--EXPECT--
15+
bool(true)

0 commit comments

Comments
 (0)