1
0
mirror of https://github.com/php/php-src.git synced 2026-03-26 01:02:25 +01:00
Files
archived-php-src/ext/session/tests/bug79091.phpt
Christoph M. Becker b510250b8e 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.
2020-03-31 08:38:23 +02:00

68 lines
1.2 KiB
PHP

--TEST--
Bug #79091 (heap use-after-free in session_create_id())
--SKIPIF--
<?php
if (!extension_loaded('session')) die('skip session extension not available');
?>
--FILE--
<?php
class MySessionHandler implements SessionHandlerInterface, SessionIdInterface, SessionUpdateTimestampHandlerInterface
{
public function close()
{
return true;
}
public function destroy($session_id)
{
return true;
}
public function gc($maxlifetime)
{
return true;
}
public function open($save_path, $session_name)
{
return true;
}
public function read($session_id)
{
return '';
}
public function write($session_id, $session_data)
{
return true;
}
public function create_sid()
{
return uniqid();
}
public function updateTimestamp($key, $val)
{
return true;
}
public function validateId($key)
{
return true;
}
}
ob_start();
var_dump(session_set_save_handler(new MySessionHandler()));
var_dump(session_start());
ob_flush();
session_create_id();
?>
--EXPECTF--
bool(true)
bool(true)
Warning: session_create_id(): Failed to create new ID in %s on line %d