com php-src: Merge branch 'PHP-5.6' into PHP-7.0: ext/session/session.c ext/session/tests/session_set_save_handler_variation4 .phpt
| From: | Yasuo Ohgaki | Date: | Wed, 16 Dec 2015 00:34:41 +0000 |
| Subject: | com php-src: Merge branch 'PHP-5.6' into PHP-7.0: ext/session/session.c ext/session/tests/session_set_save_handler_variation4 .phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-90290@lists.php.net to get a copy of this message | ||
Commit: 714f28d8e4f1a1d045b26c7d351b8c0feb429e15
Author: Yasuo Ohgaki <yohgaki@php.net> Wed, 16 Dec 2015 09:34:41 +0900
Parents: 3d3782c32859f1cd3433bc5f8ac69fd4d360bb65 e8f1c29cc96ce333fa808aba126297b77d94abdf
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=714f28d8e4f1a1d045b26c7d351b8c0feb429e15
Log:
Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
Fixed bug #71122 Session GC may not remove obsolete session data
Bugs:
https://bugs.php.net/71122
Changed paths:
MM ext/session/session.c
MM ext/session/tests/session_set_save_handler_variation4.phpt
Diff:
diff --cc ext/session/session.c
index 2f2f9f7,aec2ed0..61ccc34
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@@ -477,12 -468,35 +477,34 @@@ PHPAPI int php_session_valid_key(const
}
/* }}} */
+
+ static void php_session_gc(void) /* {{{ */
+ {
+ int nrand;
+
+ /* GC must be done before reading session data. */
+ if ((PS(mod_data) || PS(mod_user_implemented)) && PS(gc_probability) > 0) {
+ int nrdels = -1;
+
- nrand = (int) ((float) PS(gc_divisor) * php_combined_lcg(TSRMLS_C));
++ nrand = (int) ((float) PS(gc_divisor) * php_combined_lcg());
+ if (nrand < PS(gc_probability)) {
- PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels TSRMLS_CC);
++ PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels);
+ #ifdef SESSION_DEBUG
+ if (nrdels != -1) {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "purged %d expired session objects",
nrdels);
++ php_error_docref(NULL, E_NOTICE, "purged %d expired session objects", nrdels);
+ }
+ #endif
+ }
+ }
+ } /* }}} */
+
+
-static void php_session_initialize(TSRMLS_D) /* {{{ */
+static void php_session_initialize(void) /* {{{ */
{
- char *val = NULL;
- int vallen;
+ zend_string *val = NULL;
if (!PS(mod)) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "No storage module chosen - failed to initialize
session");
+ php_error_docref(NULL, E_ERROR, "No storage module chosen - failed to initialize
session");
return;
}
@@@ -504,26 -516,20 +526,29 @@@
if (PS(use_cookies)) {
PS(send_cookie) = 1;
}
+ } else if (PS(use_strict_mode) && PS(mod)->s_validate_sid &&
+ PS(mod)->s_validate_sid(&PS(mod_data), PS(id)) == FAILURE) {
+ if (PS(id)) {
+ zend_string_release(PS(id));
+ }
+ PS(id) = PS(mod)->s_create_sid(&PS(mod_data));
+ if (!PS(id)) {
+ PS(id) = php_session_create_id(NULL);
+ }
+ if (PS(use_cookies)) {
+ PS(send_cookie) = 1;
+ }
}
- /* Set session ID for compatibility for older/3rd party save handlers */
- if (!PS(use_strict_mode)) {
- php_session_reset_id(TSRMLS_C);
- PS(session_status) = php_session_active;
- }
+ php_session_reset_id();
+ PS(session_status) = php_session_active;
+ /* GC must be done before read */
+ php_session_gc();
+
/* Read data */
- php_session_track_init(TSRMLS_C);
- if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, &vallen TSRMLS_CC) == FAILURE) {
+ php_session_track_init();
+ if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, PS(gc_maxlifetime)) == FAILURE) {
/* Some broken save handler implementation returns FAILURE for non-existent session ID */
/* It's better to raise error for this, but disabled error for better compatibility */
/*
@@@ -1508,13 -1510,18 +1533,12 @@@ PHPAPI void php_session_reset_id(void)
}
/* }}} */
-PHPAPI void php_session_start(TSRMLS_D) /* {{{ */
+PHPAPI void php_session_start(void) /* {{{ */
{
- zval **ppid;
- zval **data;
+ zval *ppid;
+ zval *data;
char *p, *value;
- int nrand;
- int lensess;
-
- if (PS(use_only_cookies)) {
- PS(apply_trans_sid) = 0;
- } else {
- PS(apply_trans_sid) = PS(use_trans_sid);
- }
+ size_t lensess;
switch (PS(session_status)) {
case php_session_active:
@@@ -1620,23 -1632,8 +1644,8 @@@
PS(id) = NULL;
}
- /* GC must be done before reading session data. */
- if ((PS(mod_data) || PS(mod_user_implemented)) && PS(gc_probability) > 0) {
- int nrdels = -1;
-
- nrand = (int) ((float) PS(gc_divisor) * php_combined_lcg());
- if (nrand < PS(gc_probability)) {
- PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels);
- #ifdef SESSION_DEBUG
- if (nrdels != -1) {
- php_error_docref(NULL, E_NOTICE, "purged %d expired session objects", nrdels);
- }
- #endif
- }
- }
-
-- php_session_initialize(TSRMLS_C);
-- php_session_cache_limiter(TSRMLS_C);
++ php_session_initialize();
++ php_session_cache_limiter();
}
/* }}} */
diff --cc ext/session/tests/session_set_save_handler_variation4.phpt
index 56b8a67,6923828..67aa70c
--- a/ext/session/tests/session_set_save_handler_variation4.phpt
+++ b/ext/session/tests/session_set_save_handler_variation4.phpt
@@@ -52,9 -51,8 +52,9 @@@ ob_end_flush()
*** Testing session_set_save_handler() : variation ***
Open [%s,PHPSESSID]
- Read [%s,%s]
GC [0]
+1 deleted
+ Read [%s,%s]
array(3) {
["Blah"]=>
string(12) "Hello World!"
@@@ -67,20 -65,13 +67,12 @@@ Write [%s,%s,Blah|s:12:"Hello World!";F
Close [%s,PHPSESSID]
NULL
Open [%s,PHPSESSID]
- Read [%s,%s]
GC [0]
+1 deleted
- array(3) {
- ["Blah"]=>
- string(12) "Hello World!"
- ["Foo"]=>
- bool(false)
- ["Guff"]=>
- int(1234567890)
+ Read [%s,%s]
+ array(0) {
}
Destroy [%s,%s]
--
--Warning: unlink(%s): No such file or directory in %s on line %d
Close [%s,PHPSESSID]
bool(true)