mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
Fixed bug #71122 Session GC may not remove obsolete session data
This commit is contained in:
parent
838e4039d7
commit
e8f1c29cc9
3 changed files with 31 additions and 28 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue