Patch proposal_for_bug_71162 for Session related Bug #71162
Patch version 2015-12-18 23:05 UTC
Return to Bug #71162 |
Download this patch
Patch Revisions:
Developer: e2c2be7ed0f2f336@gmail.com
diff --git a/ext/session/session.c b/ext/session/session.c
index 61ccc34..01f1b23 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -579,20 +579,21 @@ static void php_session_save_current_state(int write) /* {{{ */
zend_string *val;
val = php_session_encode();
- if (val) {
- if (PS(lazy_write) && PS(session_vars)
- && PS(mod)->s_update_timestamp
- && PS(mod)->s_update_timestamp != php_session_update_timestamp
- && ZSTR_LEN(val) == ZSTR_LEN(PS(session_vars))
- && !memcmp(ZSTR_VAL(val), ZSTR_VAL(PS(session_vars)), ZSTR_LEN(val))
- ) {
- ret = PS(mod)->s_update_timestamp(&PS(mod_data), PS(id), val, PS(gc_maxlifetime));
- } else {
- ret = PS(mod)->s_write(&PS(mod_data), PS(id), val, PS(gc_maxlifetime));
- }
- zend_string_release(val);
+ if (!val) {
+ val = ZSTR_EMPTY_ALLOC();
+ }
+ if (PS(lazy_write) && PS(session_vars)
+ && PS(mod)->s_update_timestamp
+ && PS(mod)->s_update_timestamp != php_session_update_timestamp
+ && ZSTR_LEN(val) == ZSTR_LEN(PS(session_vars))
+ && !memcmp(ZSTR_VAL(val), ZSTR_VAL(PS(session_vars)), ZSTR_LEN(val))
+ ) {
+ ret = PS(mod)->s_update_timestamp(&PS(mod_data), PS(id), val, PS(gc_maxlifetime));
} else {
- ret = PS(mod)->s_write(&PS(mod_data), PS(id), ZSTR_EMPTY_ALLOC(), PS(gc_maxlifetime));
+ ret = PS(mod)->s_write(&PS(mod_data), PS(id), val, PS(gc_maxlifetime));
+ }
+ if (ZSTR_LEN(val)) {
+ zend_string_release(val);
}
}
diff --git a/ext/session/tests/bug71162.phpt b/ext/session/tests/bug71162.phpt
new file mode 100644
index 0000000..3028208
--- /dev/null
+++ b/ext/session/tests/bug71162.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Bug #71162 (session.lazy_write triggers write callback instead of updateTimestamp on session which remain empty)
+--INI--
+session.lazy_write=1
+--FILE--
+<?php
+class MySessionHandler implements SessionHandlerInterface#, SessionUpdateTimestampHandlerInterface
+{
+ public function close() {
+ return TRUE;
+ }
+
+ public function destroy($sessid) {
+ return TRUE;
+ }
+
+ public function gc($maxlifetime) {
+ return TRUE;
+ }
+
+ public function open($path, $sessname) {
+ return TRUE;
+ }
+
+ public function read($sessid) {
+ return '';
+ }
+
+ public function write($sessid, $sessdata) {
+ echo __FUNCTION__, PHP_EOL;
+ return TRUE;
+ }
+
+ public function updateTimestamp($sessid, $sessdata) {
+ echo __FUNCTION__, PHP_EOL;
+ return TRUE;
+ }
+}
+
+$handler = new MySessionHandler();
+session_set_save_handler($handler);
+session_id(md5(''));
+session_start();
+--EXPECT--
+updateTimestamp
+
|