diff options
author | Yasuo Ohgaki <yohgaki@php.net> | 2015-12-16 09:11:44 +0900 |
---|---|---|
committer | Yasuo Ohgaki <yohgaki@php.net> | 2015-12-16 09:15:05 +0900 |
commit | e8f1c29cc96ce333fa808aba126297b77d94abdf (patch) | |
tree | ab42619e983c00fc5641639f8a8cb546e54b1a5c /ext | |
parent | 838e4039d7fc8f79fe71091725ab0a13a5f4ad2a (diff) | |
download | php-git-e8f1c29cc96ce333fa808aba126297b77d94abdf.tar.gz |
Fixed bug #71122 Session GC may not remove obsolete session data
Diffstat (limited to 'ext')
-rw-r--r-- | ext/session/session.c | 41 | ||||
-rw-r--r-- | ext/session/tests/bug32330.phpt | 6 | ||||
-rw-r--r-- | ext/session/tests/session_set_save_handler_variation4.phpt | 12 |
3 files changed, 31 insertions, 28 deletions
diff --git a/ext/session/session.c b/ext/session/session.c index 49749219ab..aec2ed06c2 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -468,6 +468,28 @@ PHPAPI int php_session_valid_key(const char *key) /* {{{ */ } /* }}} */ + +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)); + if (nrand < PS(gc_probability)) { + PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels TSRMLS_CC); +#ifdef SESSION_DEBUG + if (nrdels != -1) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "purged %d expired session objects", nrdels); + } +#endif + } + } +} /* }}} */ + + static void php_session_initialize(TSRMLS_D) /* {{{ */ { char *val = NULL; @@ -502,6 +524,9 @@ static void php_session_initialize(TSRMLS_D) /* {{{ */ 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) { @@ -1490,7 +1515,6 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */ zval **ppid; zval **data; char *p, *value; - int nrand; int lensess; if (PS(use_only_cookies)) { @@ -1608,21 +1632,6 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */ 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(TSRMLS_C)); - if (nrand < PS(gc_probability)) { - PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels TSRMLS_CC); -#ifdef SESSION_DEBUG - if (nrdels != -1) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "purged %d expired session objects", nrdels); - } -#endif - } - } - php_session_initialize(TSRMLS_C); php_session_cache_limiter(TSRMLS_C); } diff --git a/ext/session/tests/bug32330.phpt b/ext/session/tests/bug32330.phpt index 98d442ae5c..fe83cc9504 100644 --- a/ext/session/tests/bug32330.phpt +++ b/ext/session/tests/bug32330.phpt @@ -69,17 +69,17 @@ $_SESSION['E'] = 'F'; ?> --EXPECTF-- open: path = /tmp, name = sid -read: id = %s gc: maxlifetime = %d +read: id = %s write: id = %s, data = A|s:1:"B"; close open: path = /tmp, name = sid -read: id = %s gc: maxlifetime = %d +read: id = %s destroy: id = %s close open: path = /tmp, name = sid -read: id = %s gc: maxlifetime = %d +read: id = %s write: id = %s, data = E|s:1:"F"; close diff --git a/ext/session/tests/session_set_save_handler_variation4.phpt b/ext/session/tests/session_set_save_handler_variation4.phpt index 3485f2373a..6923828409 100644 --- a/ext/session/tests/session_set_save_handler_variation4.phpt +++ b/ext/session/tests/session_set_save_handler_variation4.phpt @@ -51,8 +51,8 @@ ob_end_flush(); *** Testing session_set_save_handler() : variation *** Open [%s,PHPSESSID] -Read [%s,%s] GC [0] +Read [%s,%s] array(3) { ["Blah"]=> string(12) "Hello World!" @@ -65,15 +65,9 @@ Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;] Close [%s,PHPSESSID] NULL Open [%s,PHPSESSID] -Read [%s,%s] GC [0] -array(3) { - ["Blah"]=> - string(12) "Hello World!" - ["Foo"]=> - bool(false) - ["Guff"]=> - int(1234567890) +Read [%s,%s] +array(0) { } Destroy [%s,%s] |