diff options
-rw-r--r-- | ext/session/session.c | 31 | ||||
-rw-r--r-- | ext/session/tests/bug80889a.phpt | 35 |
2 files changed, 50 insertions, 16 deletions
diff --git a/ext/session/session.c b/ext/session/session.c index b2c05f04bd..286d108d64 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1952,12 +1952,23 @@ static int save_handler_check_session() { return SUCCESS; } +static inline void set_user_save_handler_ini(void) { + zend_string *ini_name, *ini_val; + + ini_name = zend_string_init("session.save_handler", sizeof("session.save_handler") - 1, 0); + ini_val = zend_string_init("user", sizeof("user") - 1, 0); + PS(set_handler) = 1; + zend_alter_ini_entry(ini_name, ini_val, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); + PS(set_handler) = 0; + zend_string_release_ex(ini_val, 0); + zend_string_release_ex(ini_name, 0); +} + /* {{{ Sets user-level functions */ PHP_FUNCTION(session_set_save_handler) { zval *args = NULL; int i, num_args, argc = ZEND_NUM_ARGS(); - zend_string *ini_name, *ini_val; if (argc > 0 && argc <= 2) { zval *obj = NULL; @@ -2052,13 +2063,7 @@ PHP_FUNCTION(session_set_save_handler) } if (PS(session_status) != php_session_active && (!PS(mod) || PS(mod) != &ps_mod_user)) { - ini_name = zend_string_init("session.save_handler", sizeof("session.save_handler") - 1, 0); - ini_val = zend_string_init("user", sizeof("user") - 1, 0); - PS(set_handler) = 1; - zend_alter_ini_entry(ini_name, ini_val, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - PS(set_handler) = 0; - zend_string_release_ex(ini_val, 0); - zend_string_release_ex(ini_name, 0); + set_user_save_handler_ini(); } RETURN_TRUE; @@ -2090,14 +2095,8 @@ PHP_FUNCTION(session_set_save_handler) /* remove shutdown function */ remove_user_shutdown_function("session_shutdown", sizeof("session_shutdown") - 1); - if (PS(mod) && PS(mod) != &ps_mod_user) { - ini_name = zend_string_init("session.save_handler", sizeof("session.save_handler") - 1, 0); - ini_val = zend_string_init("user", sizeof("user") - 1, 0); - PS(set_handler) = 1; - zend_alter_ini_entry(ini_name, ini_val, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - PS(set_handler) = 0; - zend_string_release_ex(ini_val, 0); - zend_string_release_ex(ini_name, 0); + if (!PS(mod) || PS(mod) != &ps_mod_user) { + set_user_save_handler_ini(); } for (i = 0; i < argc; i++) { diff --git a/ext/session/tests/bug80889a.phpt b/ext/session/tests/bug80889a.phpt new file mode 100644 index 0000000000..ff0c025382 --- /dev/null +++ b/ext/session/tests/bug80889a.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #80889 (Cannot set save handler when save_handler is invalid) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.save_handler=whatever +--FILE-- +<?php +$initHandler = ini_get('session.save_handler'); +session_set_save_handler( + function ($savePath, $sessionName) { + return true; + }, + function () { + return true; + }, + function ($id) { + return ''; + }, + function ($id, $data) { + return true; + }, + function ($id) { + return true; + }, + function ($maxlifetime) { + return true; + } +); +$setHandler = ini_get('session.save_handler'); +var_dump($initHandler, $setHandler); +?> +--EXPECT-- +string(8) "whatever" +string(4) "user" |