com php-src: Fixed bug #61470 - session_regenerate_id() does not create session file. Made session_r egenerate_id() raise error for wrong usage. :
ext/session/session.c ext/session/tests/bug614 70.phpt ext/session/tests/session_basic3.phpt e xt/session/tests/session_regenerate_id_basic.phpt ext
/session/tests/session_regenerate_id_error.phpt ext/s ession/tests/session_regenerate_id_variation1.phpt
| From: | Yasuo Ohgaki | Date: | Tue, 03 Feb 2015 03:23:00 +0000 |
| Subject: | com php-src: Fixed bug #61470 - session_regenerate_id() does not create session file. Made session_r egenerate_id() raise error for wrong usage. : ext/session/session.c ext/session/tests/bug614 70.phpt ext/session/tests/session_basic3.phpt e xt/session/tests/session_regenerate_id_basic.phpt ext /session/tests/session_regenerate_id_error.phpt ext/s ession/tests/session_regenerate_id_variation1.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-84576@lists.php.net to get a copy of this message | ||
Commit: e93042998af1fea9204e17bc5cdd13c702156d5b
Author: Yasuo Ohgaki <yohgaki@php.net> Tue, 3 Feb 2015 12:23:00 +0900
Parents: 92576c7c49a3c104bc4aea4cfa378a029bb26c86
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e93042998af1fea9204e17bc5cdd13c702156d5b
Log:
Fixed bug #61470 - session_regenerate_id() does not create session file.
Made session_regenerate_id() raise error for wrong usage.
Bugs:
https://bugs.php.net/61470
Changed paths:
M ext/session/session.c
M ext/session/tests/bug61470.phpt
M ext/session/tests/session_basic3.phpt
M ext/session/tests/session_regenerate_id_basic.phpt
M ext/session/tests/session_regenerate_id_error..phpt
M ext/session/tests/session_regenerate_id_variation1.phpt
diff --git a/ext/session/session.c b/ext/session/session.c index 010de35..553f1ed 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 8be1a54..d8b4c20 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 08e3aae..49c2203 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 910620a..cdf2bb1 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 9e119f1..9c94d85 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 95d4a77..ca0ef35 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
diff --git a/ext/session/session.c b/ext/session/session.c index 010de35..553f1ed 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 8be1a54..d8b4c20 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 08e3aae..49c2203 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 910620a..cdf2bb1 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 9e119f1..9c94d85 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 95d4a77..ca0ef35 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