Fixed bug #61470 - session_regenerate_id() does not create session file.

Made session_regenerate_id() raise error for wrong usage.
This commit is contained in:
Yasuo Ohgaki 2015-02-03 12:23:00 +09:00
parent 92576c7c49
commit e93042998a
6 changed files with 88 additions and 32 deletions

View File

@ -2010,6 +2010,7 @@ static PHP_FUNCTION(session_id)
static PHP_FUNCTION(session_regenerate_id)
{
zend_bool del_ses = 0;
zend_string *data = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &del_ses) == FAILURE) {
return;
@ -2020,26 +2021,31 @@ static PHP_FUNCTION(session_regenerate_id)
RETURN_FALSE;
}
if (PS(session_status) == php_session_active) {
if (PS(id)) {
if (del_ses && PS(mod)->s_destroy(&PS(mod_data), PS(id)) == FAILURE) {
php_error_docref(NULL, E_WARNING, "Session object destruction failed");
RETURN_FALSE;
}
zend_string_release(PS(id));
PS(id) = NULL;
}
PS(id) = PS(mod)->s_create_sid(&PS(mod_data));
if (PS(id)) {
PS(send_cookie) = 1;
php_session_reset_id();
RETURN_TRUE;
} else {
PS(id) = STR_EMPTY_ALLOC();
}
if (PS(session_status) != php_session_active) {
php_error_docref(NULL, E_WARNING, "Cannot regenerate session id - session is not active");
RETURN_FALSE;
}
RETURN_FALSE;
/* Keep current session data */
data = php_session_encode();
if (del_ses && PS(mod)->s_destroy(&PS(mod_data), PS(id)) == FAILURE) {
php_error_docref(NULL, E_WARNING, "Session object destruction failed");
}
php_rshutdown_session_globals();
php_rinit_session_globals();
php_session_initialize();
/* Restore session data */
if (data) {
if (PS(session_vars)) {
zend_string_release(PS(session_vars));
PS(session_vars) = NULL;
}
php_session_decode(data);
zend_string_release(data);
}
RETURN_TRUE;
}
/* }}} */

View File

@ -2,8 +2,6 @@
Bug #61470 (session_regenerate_id() does not create session file)
--SKIPIF--
<?php include('skipif.inc'); ?>
--XFAIL--
Semantecs of create id seems changed. Will be fixed soon.
--INI--
--FILE--
<?php
@ -24,6 +22,6 @@ var_dump(is_file($file2));
unlink($file1);
unlink($file2);
--EXPECT--
bool(true);
bool(true);
bool(true)
bool(true)

View File

@ -180,15 +180,15 @@ ob_end_flush();
*** Testing basic session functionality : variation3 use_trans_sid ***
*** Test trans sid ***
<a href="/?PHPSESSID=testid&PHPSESSID=testid">test</a>
<a href="/?PHPSESSID=testid&PHPSESSID=testid#bar">test</a>
<a href="/?foo&PHPSESSID=testid&PHPSESSID=testid">test</a>
<a href="/?foo&PHPSESSID=testid&PHPSESSID=testid#bar">test</a>
<a href="/?foo=var&PHPSESSID=testid&PHPSESSID=testid">test</a>
<a href="/?foo=var&PHPSESSID=testid&PHPSESSID=testid#bar">test</a>
<a href="file.php?PHPSESSID=testid&PHPSESSID=testid">test</a>
<a href="file.php?foo&PHPSESSID=testid&PHPSESSID=testid">test</a>
<a href="file.php?foo=var&PHPSESSID=testid&PHPSESSID=testid">test</a>
<a href="/?PHPSESSID=testid">test</a>
<a href="/?PHPSESSID=testid#bar">test</a>
<a href="/?foo&PHPSESSID=testid">test</a>
<a href="/?foo&PHPSESSID=testid#bar">test</a>
<a href="/?foo=var&PHPSESSID=testid">test</a>
<a href="/?foo=var&PHPSESSID=testid#bar">test</a>
<a href="file.php?PHPSESSID=testid">test</a>
<a href="file.php?foo&PHPSESSID=testid">test</a>
<a href="file.php?foo=var&PHPSESSID=testid">test</a>
<a href="http://php.net">test</a>
<a href="http://php.net/">test</a>
<a href="http://php.net/#bar">test</a>

View File

@ -31,12 +31,16 @@ ob_end_flush();
--EXPECTF--
*** Testing session_regenerate_id() : basic functionality ***
string(0) ""
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
string(0) ""
bool(true)
bool(true)
string(%d) "%s"
bool(true)
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
string(0) ""
Done

View File

@ -96,63 +96,103 @@ ob_end_flush();
*** Testing session_regenerate_id() : error functionality ***
-- Iteration 1 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 2 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 3 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 4 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 5 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 6 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 7 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 8 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 9 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 10 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 11 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 12 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 13 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 14 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 15 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 16 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 17 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 18 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 19 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 20 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 21 --
@ -161,9 +201,13 @@ Warning: session_regenerate_id() expects parameter 1 to be boolean, object given
NULL
-- Iteration 22 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 23 --
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
-- Iteration 24 --

View File

@ -31,12 +31,16 @@ ob_end_flush();
--EXPECTF--
*** Testing session_regenerate_id() : variation ***
string(0) ""
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
string(0) ""
bool(true)
bool(true)
string(%d) "%s"
bool(true)
Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in %s on line %d
bool(false)
string(0) ""
Done