summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYasuo Ohgaki <yohgaki@php.net>2015-12-16 09:36:26 +0900
committerYasuo Ohgaki <yohgaki@php.net>2015-12-16 09:36:26 +0900
commit3381264a33ae87281a3ece75d80a2ed16af597b3 (patch)
tree10f37aec5037ebf123155f19e3b9f791b6379663
parentc88ffa9a5673cb3141660626ba1921671f0b84d6 (diff)
parent707e1c47109376bd52c393c9088273fe8d09d3bd (diff)
downloadphp-git-3381264a33ae87281a3ece75d80a2ed16af597b3.tar.gz
Merge branch 'PHP-7.0'
* PHP-7.0: Fixed bug #71122 Session GC may not remove obsolete session data
-rw-r--r--ext/session/session.c45
-rw-r--r--ext/session/tests/bug32330.phpt6
-rw-r--r--ext/session/tests/session_set_save_handler_variation4.phpt14
-rw-r--r--ext/session/tests/session_set_save_handler_variation5.phpt8
4 files changed, 36 insertions, 37 deletions
diff --git a/ext/session/session.c b/ext/session/session.c
index 2f2f9f7e46..61ccc34317 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -477,6 +477,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());
+ 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
+ }
+ }
+} /* }}} */
+
+
static void php_session_initialize(void) /* {{{ */
{
zend_string *val = NULL;
@@ -521,6 +543,9 @@ static void php_session_initialize(void) /* {{{ */
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();
if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, PS(gc_maxlifetime)) == FAILURE) {
@@ -1513,7 +1538,6 @@ PHPAPI void php_session_start(void) /* {{{ */
zval *ppid;
zval *data;
char *p, *value;
- int nrand;
size_t lensess;
switch (PS(session_status)) {
@@ -1620,23 +1644,8 @@ PHPAPI void php_session_start(void) /* {{{ */
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 --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 56b8a67f2a..67aa70c4af 100644
--- a/ext/session/tests/session_set_save_handler_variation4.phpt
+++ b/ext/session/tests/session_set_save_handler_variation4.phpt
@@ -52,9 +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 +67,12 @@ 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]
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)
diff --git a/ext/session/tests/session_set_save_handler_variation5.phpt b/ext/session/tests/session_set_save_handler_variation5.phpt
index 4e67365b45..4c1687cac6 100644
--- a/ext/session/tests/session_set_save_handler_variation5.phpt
+++ b/ext/session/tests/session_set_save_handler_variation5.phpt
@@ -62,9 +62,9 @@ string(0) ""
bool(true)
Open [%s,PHPSESSID]
CreateID [PHPT-%d]
-Read [%s,PHPT-%d]
GC [0]
1 deleted
+Read [%s,PHPT-%d]
bool(true)
string(%d) "PHPT-%d"
Write [%s,PHPT-%d,]
@@ -76,9 +76,9 @@ string(%d) "PHPT-%d"
bool(true)
Open [%s,PHPSESSID]
ValidateID [%s,PHPT-%d]
-Read [%s,PHPT-%d]
GC [0]
1 deleted
+Read [%s,PHPT-%d]
bool(true)
Write [%s,PHPT-%d,]
Close [%s,PHPSESSID]
@@ -88,12 +88,10 @@ string(%d) "PHPT-%d"
string(%d) "PHPT-%d"
Open [%s,PHPSESSID]
ValidateID [%s,PHPT-%d]
-Read [%s,PHPT-%d]
GC [0]
1 deleted
+Read [%s,PHPT-%d]
bool(true)
Destroy [%s,PHPT-%d]
-
-Warning: unlink(%ssession_test_PHPT-%s): No such file or directory in %ssave_handler.inc on line %d
Close [%s,PHPSESSID]
bool(true)