Skip to content

Commit 72cb473

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix GH-9583: session_create_id() fails with user defined save handler that doesn't have a validateId() method
2 parents cfee252 + 8b11525 commit 72cb473

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
- Opcache:
1010
. Added indirect call reduction for jit on x86 architectures. (wxue1)
1111

12+
- Session:
13+
. Fixed bug GH-9583 (session_create_id() fails with user defined save handler
14+
that doesn't have a validateId() method). (Girgias)
15+
1216
29 Sep 2022, PHP 8.1.11
1317

1418
- Core:

ext/session/session.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,9 @@ PHPAPI int php_session_register_module(const ps_module *ptr) /* {{{ */
10821082
/* }}} */
10831083

10841084
/* Dummy PS module function */
1085+
/* We consider any ID valid, so we return FAILURE to indicate that a session doesn't exist */
10851086
PHPAPI int php_session_validate_sid(PS_VALIDATE_SID_ARGS) {
1086-
return SUCCESS;
1087+
return FAILURE;
10871088
}
10881089

10891090
/* Dummy PS module function */

ext/session/tests/gh9583.phpt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
GH-9583: session_create_id() fails with user defined save handler that doesn't have a validateId() method
3+
--EXTENSIONS--
4+
session
5+
--SKIPIF--
6+
<?php include('skipif.inc'); ?>
7+
--FILE--
8+
<?php
9+
10+
class SessionHandlerTester implements \SessionHandlerInterface
11+
{
12+
13+
public function close(): bool { return true; }
14+
15+
public function destroy($id): bool { return true; }
16+
17+
public function gc($max_lifetime): int|false { return 1; }
18+
19+
public function open($path, $name): bool { return true; }
20+
21+
public function read($id): string { return ''; }
22+
23+
public function write($id, $data): bool { return true; }
24+
25+
//public function create_sid() { return uniqid(); }
26+
27+
//public function validateId($key) { return true; }
28+
}
29+
30+
$obj = new SessionHandlerTester();
31+
ini_set('session.use_strict_mode','1');
32+
session_set_save_handler($obj);
33+
session_start();
34+
35+
echo "\nvalidateId() ".(method_exists($obj,'validateId')?('returns '.($obj->validateId(1)?'true':'false')):'is commented out');
36+
echo "\n";
37+
$sessionId = session_create_id();
38+
echo "\nSession ID:".$sessionId;
39+
echo "\n";
40+
41+
?>
42+
--EXPECTF--
43+
validateId() is commented out
44+
45+
Session ID:%s

0 commit comments

Comments
 (0)