summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYasuo Ohgaki <yohgaki@php.net>2015-02-03 12:23:00 +0900
committerYasuo Ohgaki <yohgaki@php.net>2015-02-03 12:23:00 +0900
commite93042998af1fea9204e17bc5cdd13c702156d5b (patch)
tree6a79f9ec3d83ce88d8b65c8be01a0ffc02653a8a
parent92576c7c49a3c104bc4aea4cfa378a029bb26c86 (diff)
downloadphp-git-e93042998af1fea9204e17bc5cdd13c702156d5b.tar.gz
Fixed bug #61470 - session_regenerate_id() does not create session file.
Made session_regenerate_id() raise error for wrong usage.
-rw-r--r--ext/session/session.c40
-rw-r--r--ext/session/tests/bug61470.phpt6
-rw-r--r--ext/session/tests/session_basic3.phpt18
-rw-r--r--ext/session/tests/session_regenerate_id_basic.phpt4
-rw-r--r--ext/session/tests/session_regenerate_id_error.phpt44
-rw-r--r--ext/session/tests/session_regenerate_id_variation1.phpt4
6 files changed, 86 insertions, 30 deletions
diff --git a/ext/session/session.c b/ext/session/session.c
index 010de352b9..553f1ede66 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -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;
- }
+ if (PS(session_status) != php_session_active) {
+ php_error_docref(NULL, E_WARNING, "Cannot regenerate session id - session is not active");
+ RETURN_FALSE;
+ }
- 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();
+ /* 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_FALSE;
+ RETURN_TRUE;
}
/* }}} */
diff --git a/ext/session/tests/bug61470.phpt b/ext/session/tests/bug61470.phpt
index 8be1a540b5..d8b4c2014f 100644
--- a/ext/session/tests/bug61470.phpt
+++ b/ext/session/tests/bug61470.phpt
@@ -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)
diff --git a/ext/session/tests/session_basic3.phpt b/ext/session/tests/session_basic3.phpt
index 08e3aae295..49c22032bd 100644
--- a/ext/session/tests/session_basic3.phpt
+++ b/ext/session/tests/session_basic3.phpt
@@ -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>
diff --git a/ext/session/tests/session_regenerate_id_basic.phpt b/ext/session/tests/session_regenerate_id_basic.phpt
index 910620a66f..cdf2bb1f2b 100644
--- a/ext/session/tests/session_regenerate_id_basic.phpt
+++ b/ext/session/tests/session_regenerate_id_basic.phpt
@@ -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
diff --git a/ext/session/tests/session_regenerate_id_error.phpt b/ext/session/tests/session_regenerate_id_error.phpt
index 9e119f17fb..9c94d8564b 100644
--- a/ext/session/tests/session_regenerate_id_error.phpt
+++ b/ext/session/tests/session_regenerate_id_error.phpt
@@ -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 --
diff --git a/ext/session/tests/session_regenerate_id_variation1.phpt b/ext/session/tests/session_regenerate_id_variation1.phpt
index 95d4a77c8e..ca0ef35b10 100644
--- a/ext/session/tests/session_regenerate_id_variation1.phpt
+++ b/ext/session/tests/session_regenerate_id_variation1.phpt
@@ -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