com php-src: Merge branch 'PHP-5.6' into PHP-7.0: ext/session/m od_user.c ext/session/mod_user_class.c ext/sessio n/session.c
ext/session/tests/bug60634_error_ 1.phpt
| From: | Yasuo Ohgaki | Date: | Fri, 15 Jan 2016 07:24:22 +0000 |
| Subject: | com php-src: Merge branch 'PHP-5.6' into PHP-7.0: ext/session/m od_user.c ext/session/mod_user_class.c ext/sessio n/session.c ext/session/tests/bug60634_error_ 1.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-90652@lists.php.net to get a copy of this message | ||
Commit: 34ff7bbeb19b08dc1036836045e30d88599baafb
Author: Yasuo Ohgaki <yohgaki@php.net> Fri, 15 Jan 2016 16:24:22 +0900
Parents: 132d919c8597b3a06b2f03d04d8d8df5614dba4c bfb9307b2d679a91e138fd876880470ece60942b
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=34ff7bbeb19b08dc1036836045e30d88599baafb
Log:
Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
Fixed bug #69111 (Crash in SessionHandler::read()). Made session save handler abuse much harder
than before.
Bugs:
https://bugs.php.net/69111
Changed paths:
MM ext/session/mod_user.c
MM ext/session/mod_user_class..c
MM ext/session/session.c
MM ext/session/tests/bug60634_error_1..phpt
Diff:
diff --cc ext/session/mod_user.c
index e6f1628,de2df9d..c7c09ff
--- a/ext/session/mod_user.c
+++ b/ext/session/mod_user.c
@@@ -82,10 -88,19 +82,19 @@@ PS_OPEN_FUNC(user
return FAILURE;
}
- SESS_ZVAL_STRING((char*)save_path, args[0]);
- SESS_ZVAL_STRING((char*)session_name, args[1]);
+ ZVAL_STRING(&args[0], (char*)save_path);
+ ZVAL_STRING(&args[1], (char*)session_name);
- ps_call_handler(&PSF(open), 2, args, &retval);
+ zend_try {
- retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC);
++ ps_call_handler(&PSF(open), 2, args, &retval);
+ } zend_catch {
+ PS(session_status) = php_session_none;
- if (retval) {
++ if (!Z_ISUNDEF(retval)) {
+ zval_ptr_dtor(&retval);
+ }
+ zend_bailout();
+ } zend_end_try();
+
PS(mod_user_implemented) = 1;
FINISH;
diff --cc ext/session/mod_user_class.c
index 59b44f5,6768bec..a774d4b
--- a/ext/session/mod_user_class.c
+++ b/ext/session/mod_user_class.c
@@@ -22,10 -22,14 +22,14 @@@
#include "php_session.h"
#define PS_SANITY_CHECK \
+ if (PS(session_status) != php_session_active) { \
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session is not active"); \
++ php_error_docref(NULL, E_WARNING, "Session is not active"); \
+ RETURN_FALSE; \
+ } \
if (PS(default_mod) == NULL) { \
- php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Cannot call default session handler");
\
+ php_error_docref(NULL, E_CORE_ERROR, "Cannot call default session handler"); \
RETURN_FALSE; \
- }
+ }
#define PS_SANITY_CHECK_IS_OPEN \
PS_SANITY_CHECK; \
@@@ -39,7 -43,7 +43,8 @@@
PHP_METHOD(SessionHandler, open)
{
char *save_path = NULL, *session_name = NULL;
- int ret, save_path_len, session_name_len;
+ size_t save_path_len, session_name_len;
++ int ret;
PS_SANITY_CHECK;
@@@ -48,7 -52,14 +53,15 @@@
}
PS(mod_user_is_open) = 1;
- RETVAL_BOOL(SUCCESS == PS(default_mod)->s_open(&PS(mod_data), save_path, session_name));
++
+ zend_try {
- ret =PS(default_mod)->s_open(&PS(mod_data), save_path, session_name TSRMLS_CC);
++ ret = PS(default_mod)->s_open(&PS(mod_data), save_path, session_name);
+ } zend_catch {
+ PS(session_status) = php_session_none;
+ zend_bailout();
+ } zend_end_try();
+
+ RETVAL_BOOL(SUCCESS == ret);
}
/* }}} */
@@@ -61,9 -74,17 +76,17 @@@ PHP_METHOD(SessionHandler, close
// don't return on failure, since not closing the default handler
// could result in memory leaks or other nasties
zend_parse_parameters_none();
-
+
PS(mod_user_is_open) = 0;
- RETVAL_BOOL(SUCCESS == PS(default_mod)->s_close(&PS(mod_data)));
+
+ zend_try {
- ret = PS(default_mod)->s_close(&PS(mod_data) TSRMLS_CC);
++ ret = PS(default_mod)->s_close(&PS(mod_data));
+ } zend_catch {
+ PS(session_status) = php_session_none;
+ zend_bailout();
+ } zend_end_try();
+
+ RETVAL_BOOL(SUCCESS == ret);
}
/* }}} */
diff --cc ext/session/session.c
index 4b0643d,cbcd20d..b4a63bd
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@@ -94,15 -86,15 +94,16 @@@ zend_class_entry *php_session_update_ti
return FAILURE; \
}
-static void php_session_send_cookie(TSRMLS_D);
-static void php_session_abort(TSRMLS_D);
+#define APPLY_TRANS_SID (PS(use_trans_sid) && !PS(use_only_cookies))
+
+static void php_session_send_cookie(void);
+static void php_session_abort(void);
/* Dispatched by RINIT and by php_session_destroy */
-static inline void php_rinit_session_globals(TSRMLS_D) /* {{{ */
+static inline void php_rinit_session_globals(void) /* {{{ */
{
/* Do NOT init PS(mod_user_names) here! */
-
+ /* TODO: These could be moved to MINIT and removed. These should be initialized by
php_rshutdown_session_globals() always when execution is finished. */
PS(id) = NULL;
PS(session_status) = php_session_none;
PS(mod_data) = NULL;
@@@ -127,13 -118,12 +128,18 @@@ static inline void php_rshutdown_sessio
} zend_end_try();
}
if (PS(id)) {
- efree(PS(id));
+ zend_string_release(PS(id));
PS(id) = NULL;
}
++
+ if (PS(session_vars)) {
+ zend_string_release(PS(session_vars));
+ PS(session_vars) = NULL;
+ }
++
+ /* User save handlers may end up directly here by misuse, bugs in user script, etc. */
+ /* Set session status to prevent error while restoring save handler INI value. */
+ PS(session_status) = php_session_none;
}
/* }}} */
@@@ -1659,22 -1653,22 +1665,22 @@@ PHPAPI void php_session_start(void) /*
}
/* }}} */
-static void php_session_flush(TSRMLS_D) /* {{{ */
+static void php_session_flush(int write) /* {{{ */
{
if (PS(session_status) == php_session_active) {
- PS(session_status) = php_session_none;
- php_session_save_current_state(TSRMLS_C);
+ php_session_save_current_state(write);
+ PS(session_status) = php_session_none;
}
}
/* }}} */
-static void php_session_abort(TSRMLS_D) /* {{{ */
+static void php_session_abort(void) /* {{{ */
{
if (PS(session_status) == php_session_active) {
- PS(session_status) = php_session_none;
if (PS(mod_data) || PS(mod_user_implemented)) {
- PS(mod)->s_close(&PS(mod_data) TSRMLS_CC);
+ PS(mod)->s_close(&PS(mod_data));
}
+ PS(session_status) = php_session_none;
}
}
/* }}} */
diff --cc ext/session/tests/bug60634_error_1.phpt
index d0733f5,7388ba0..fa76ff5
--- a/ext/session/tests/bug60634_error_1.phpt
+++ b/ext/session/tests/bug60634_error_1.phpt
@@@ -41,13 -40,20 +41,19 @@@ session_start()
session_write_close();
echo "um, hi\n";
+ /*
-FIXME: Since session module try to write/close session data in
-RSHUTDOWN, write() is executed twices. This is caused by undefined
-function error and zend_bailout(). Current session module codes
-depends on this behavior. These codes should be modified to remove
-multiple write().
++FIXME: Something wrong. It should try to close after error, otherwise session
++may keep "open" state.
+ */
+
?>
--EXPECTF--
write: goodbye cruel world
-Fatal error: Call to undefined function undefined_function() in %s on line %d
-write: goodbye cruel world
+Fatal error: Uncaught Error: Call to undefined function undefined_function() in %s:%d
+Stack trace:
+#0 [internal function]: write(%s, '')
+#1 %s(%d): session_write_close()
+#2 {main}
+ thrown in %s on line %d
+
-Fatal error: Call to undefined function undefined_function() in %s on line %d
-close: goodbye cruel world