diff options
| author | Jakub Zelenka <bukka@php.net> | 2016-02-29 19:31:20 +0000 |
|---|---|---|
| committer | Jakub Zelenka <bukka@php.net> | 2016-02-29 19:31:20 +0000 |
| commit | 70141093a731049ee9220e9e965f61ded56ed4d5 (patch) | |
| tree | 6e67b382253a186889bfdc37c31062d6fb9880d9 /ext/session | |
| parent | e453af3851daf08f5af9b45fc7819c3a9c336f1e (diff) | |
| parent | 97294aca7e066443291cc2d77f8674ac23eabb32 (diff) | |
| download | php-git-70141093a731049ee9220e9e965f61ded56ed4d5.tar.gz | |
Merge branch 'master' into openssl_aead
Diffstat (limited to 'ext/session')
29 files changed, 303 insertions, 108 deletions
diff --git a/ext/session/mod_mm.c b/ext/session/mod_mm.c index 1978caed3c..3f69897556 100644 --- a/ext/session/mod_mm.c +++ b/ext/session/mod_mm.c @@ -29,6 +29,7 @@ #include <sys/types.h> #include <fcntl.h> +#include "php_stdint.h" #include "php_session.h" #include "mod_mm.h" #include "SAPI.h" @@ -39,14 +40,11 @@ #define PS_MM_FILE "session_mm_" -/* For php_uint32 */ -#include "ext/standard/basic_functions.h" - /* This list holds all data associated with one session. */ typedef struct ps_sd { struct ps_sd *next; - php_uint32 hv; /* hash value of key */ + uint32_t hv; /* hash value of key */ time_t ctime; /* time of last change */ void *data; size_t datalen; /* amount of valid data */ @@ -57,8 +55,8 @@ typedef struct ps_sd { typedef struct { MM *mm; ps_sd **hash; - php_uint32 hash_max; - php_uint32 hash_cnt; + uint32_t hash_max; + uint32_t hash_cnt; pid_t owner; } ps_mm; @@ -70,9 +68,9 @@ static ps_mm *ps_mm_instance = NULL; # define ps_mm_debug(a) #endif -static inline php_uint32 ps_sd_hash(const char *data, int len) +static inline uint32_t ps_sd_hash(const char *data, int len) { - php_uint32 h; + uint32_t h; const char *e = data + len; for (h = 2166136261U; data < e; ) { @@ -85,7 +83,7 @@ static inline php_uint32 ps_sd_hash(const char *data, int len) static void hash_split(ps_mm *data) { - php_uint32 nmax; + uint32_t nmax; ps_sd **nhash; ps_sd **ohash, **ehash; ps_sd *ps, *next; @@ -114,7 +112,7 @@ static void hash_split(ps_mm *data) static ps_sd *ps_sd_new(ps_mm *data, const char *key) { - php_uint32 hv, slot; + uint32_t hv, slot; ps_sd *sd; int keylen; @@ -155,7 +153,7 @@ static ps_sd *ps_sd_new(ps_mm *data, const char *key) static void ps_sd_destroy(ps_mm *data, ps_sd *sd) { - php_uint32 slot; + uint32_t slot; slot = ps_sd_hash(sd->key, strlen(sd->key)) & data->hash_max; @@ -180,7 +178,7 @@ static void ps_sd_destroy(ps_mm *data, ps_sd *sd) static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw) { - php_uint32 hv, slot; + uint32_t hv, slot; ps_sd *ret, *prev; hv = ps_sd_hash(key, strlen(key)); diff --git a/ext/session/mod_user.c b/ext/session/mod_user.c index e6f162855a..c7c09ff781 100644 --- a/ext/session/mod_user.c +++ b/ext/session/mod_user.c @@ -85,7 +85,16 @@ PS_OPEN_FUNC(user) ZVAL_STRING(&args[0], (char*)save_path); ZVAL_STRING(&args[1], (char*)session_name); - ps_call_handler(&PSF(open), 2, args, &retval); + zend_try { + ps_call_handler(&PSF(open), 2, args, &retval); + } zend_catch { + PS(session_status) = php_session_none; + if (!Z_ISUNDEF(retval)) { + zval_ptr_dtor(&retval); + } + zend_bailout(); + } zend_end_try(); + PS(mod_user_implemented) = 1; FINISH; diff --git a/ext/session/mod_user_class.c b/ext/session/mod_user_class.c index 59b44f5f6f..a774d4bf9c 100644 --- a/ext/session/mod_user_class.c +++ b/ext/session/mod_user_class.c @@ -22,6 +22,10 @@ #include "php_session.h" #define PS_SANITY_CHECK \ + if (PS(session_status) != php_session_active) { \ + php_error_docref(NULL, E_WARNING, "Session is not active"); \ + RETURN_FALSE; \ + } \ if (PS(default_mod) == NULL) { \ php_error_docref(NULL, E_CORE_ERROR, "Cannot call default session handler"); \ RETURN_FALSE; \ @@ -40,6 +44,7 @@ PHP_METHOD(SessionHandler, open) { char *save_path = NULL, *session_name = NULL; size_t save_path_len, session_name_len; + int ret; PS_SANITY_CHECK; @@ -48,7 +53,15 @@ PHP_METHOD(SessionHandler, open) } 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); + } zend_catch { + PS(session_status) = php_session_none; + zend_bailout(); + } zend_end_try(); + + RETVAL_BOOL(SUCCESS == ret); } /* }}} */ @@ -56,6 +69,8 @@ PHP_METHOD(SessionHandler, open) Wraps the old close handler */ PHP_METHOD(SessionHandler, close) { + int ret; + PS_SANITY_CHECK_IS_OPEN; // don't return on failure, since not closing the default handler @@ -63,7 +78,15 @@ PHP_METHOD(SessionHandler, close) 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)); + } zend_catch { + PS(session_status) = php_session_none; + zend_bailout(); + } zend_end_try(); + + RETVAL_BOOL(SUCCESS == ret); } /* }}} */ diff --git a/ext/session/session.c b/ext/session/session.c index 52ba7e300a..866fab68a4 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -97,11 +97,13 @@ zend_class_entry *php_session_update_timestamp_iface_entry; #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(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; @@ -129,10 +131,15 @@ static inline void php_rshutdown_session_globals(void) /* {{{ */ 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; } /* }}} */ @@ -503,7 +510,10 @@ static void php_session_initialize(void) /* {{{ */ { zend_string *val = NULL; + PS(session_status) = php_session_active; + if (!PS(mod)) { + PS(session_status) = php_session_disabled; php_error_docref(NULL, E_ERROR, "No storage module chosen - failed to initialize session"); return; } @@ -512,14 +522,19 @@ static void php_session_initialize(void) /* {{{ */ if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE /* || PS(mod_data) == NULL */ /* FIXME: open must set valid PS(mod_data) with success */ ) { + php_session_abort(); php_error_docref(NULL, E_ERROR, "Failed to initialize storage module: %s (path: %s)", PS(mod)->s_name, PS(save_path)); return; } /* If there is no ID, use session module to create one */ - if (!PS(id)) { + if (!PS(id) || !ZSTR_VAL(PS(id))[0]) { + if (PS(id)) { + zend_string_release(PS(id)); + } PS(id) = PS(mod)->s_create_sid(&PS(mod_data)); if (!PS(id)) { + php_session_abort(); php_error_docref(NULL, E_ERROR, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path)); return; } @@ -541,20 +556,20 @@ 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) { + php_session_abort(); /* Some broken save handler implementation returns FAILURE for non-existent session ID */ /* It's better to raise error for this, but disabled error for better compatibility */ - /* - php_error_docref(NULL, E_NOTICE, "Failed to read session data: %s (path: %s)", PS(mod)->s_name, PS(save_path)); - */ + php_error_docref(NULL, E_WARNING, "Failed to read session data: %s (path: %s)", PS(mod)->s_name, PS(save_path)); + return; } + + /* GC must be done after read */ + php_session_gc(); + if (PS(session_vars)) { zend_string_release(PS(session_vars)); PS(session_vars) = NULL; @@ -597,11 +612,16 @@ static void php_session_save_current_state(int write) /* {{{ */ } if ((ret == FAILURE) && !EG(exception)) { - php_error_docref(NULL, E_WARNING, "Failed to write session data (%s). Please " - "verify that the current setting of session.save_path " - "is correct (%s)", - PS(mod)->s_name, - PS(save_path)); + if (!PS(mod_user_implemented)) { + php_error_docref(NULL, E_WARNING, "Failed to write session data (%s). Please " + "verify that the current setting of session.save_path " + "is correct (%s)", + PS(mod)->s_name, + PS(save_path)); + } else { + php_error_docref(NULL, E_WARNING, "Failed to write session data using user " + "defined save handler. (session.save_path: %s)", PS(save_path)); + } } } } @@ -1102,7 +1122,7 @@ static ps_serializer ps_serializers[MAX_SERIALIZERS + 1] = { PHPAPI int php_session_register_serializer(const char *name, zend_string *(*encode)(PS_SERIALIZER_ENCODE_ARGS), int (*decode)(PS_SERIALIZER_DECODE_ARGS)) /* {{{ */ { - int ret = -1; + int ret = FAILURE; int i; for (i = 0; i < MAX_SERIALIZERS; i++) { @@ -1111,7 +1131,7 @@ PHPAPI int php_session_register_serializer(const char *name, zend_string *(*enco ps_serializers[i].encode = encode; ps_serializers[i].decode = decode; ps_serializers[i + 1].name = NULL; - ret = 0; + ret = SUCCESS; break; } } @@ -1133,13 +1153,13 @@ static ps_module *ps_modules[MAX_MODULES + 1] = { PHPAPI int php_session_register_module(ps_module *ptr) /* {{{ */ { - int ret = -1; + int ret = FAILURE; int i; for (i = 0; i < MAX_MODULES; i++) { if (!ps_modules[i]) { ps_modules[i] = ptr; - ret = 0; + ret = SUCCESS; break; } } @@ -1288,11 +1308,13 @@ static int php_session_cache_limiter(void) /* {{{ */ php_session_cache_limiter_t *lim; if (PS(cache_limiter)[0] == '\0') return 0; + if (PS(session_status) != php_session_active) return -1; if (SG(headers_sent)) { const char *output_start_filename = php_output_get_start_filename(); int output_start_lineno = php_output_get_start_lineno(); + php_session_abort(); if (output_start_filename) { php_error_docref(NULL, E_WARNING, "Cannot send session cache limiter - headers already sent (output started at %s:%d)", output_start_filename, output_start_lineno); } else { @@ -1652,8 +1674,8 @@ PHPAPI void php_session_start(void) /* {{{ */ 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(write); + PS(session_status) = php_session_none; } } /* }}} */ @@ -1661,10 +1683,10 @@ static void php_session_flush(int write) /* {{{ */ 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)); } + PS(session_status) = php_session_none; } } /* }}} */ @@ -2039,13 +2061,13 @@ static PHP_FUNCTION(session_regenerate_id) return; } - if (SG(headers_sent) && PS(use_cookies)) { - php_error_docref(NULL, E_WARNING, "Cannot regenerate session id - headers already sent"); + if (PS(session_status) != php_session_active) { + php_error_docref(NULL, E_WARNING, "Cannot regenerate session id - session is not active"); RETURN_FALSE; } - if (PS(session_status) != php_session_active) { - php_error_docref(NULL, E_WARNING, "Cannot regenerate session id - session is not active"); + if (SG(headers_sent) && PS(use_cookies)) { + php_error_docref(NULL, E_WARNING, "Cannot regenerate session id - headers already sent"); RETURN_FALSE; } @@ -2081,15 +2103,18 @@ static PHP_FUNCTION(session_regenerate_id) PS(session_vars) = NULL; } zend_string_release(PS(id)); - PS(id) = PS(mod)->s_create_sid(&PS(mod_data)); - if (!PS(id)) { + PS(id) = NULL; + + if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) { PS(session_status) = php_session_none; - php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to create new session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path)); + php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to open session: %s (path: %s)", PS(mod)->s_name, PS(save_path)); RETURN_FALSE; } - if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) { + + PS(id) = PS(mod)->s_create_sid(&PS(mod_data)); + if (!PS(id)) { PS(session_status) = php_session_none; - php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to create(open) session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path)); + php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to create new session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path)); RETURN_FALSE; } if (PS(use_strict_mode) && PS(mod)->s_validate_sid && @@ -2097,6 +2122,7 @@ static PHP_FUNCTION(session_regenerate_id) zend_string_release(PS(id)); PS(id) = PS(mod)->s_create_sid(&PS(mod_data)); if (!PS(id)) { + PS(mod)->s_close(&PS(mod_data)); PS(session_status) = php_session_none; php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to create session ID by collision: %s (path: %s)", PS(mod)->s_name, PS(save_path)); RETURN_FALSE; @@ -2104,6 +2130,7 @@ static PHP_FUNCTION(session_regenerate_id) } /* Read is required to make new session data at this point. */ if (PS(mod)->s_read(&PS(mod_data), PS(id), &data, PS(gc_maxlifetime)) == FAILURE) { + PS(mod)->s_close(&PS(mod_data)); PS(session_status) = php_session_none; php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to create(read) session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path)); RETURN_FALSE; @@ -2275,11 +2302,6 @@ static PHP_FUNCTION(session_start) RETURN_FALSE; } - if (PS(id) && !(ZSTR_LEN(PS(id)))) { - php_error_docref(NULL, E_WARNING, "Cannot start session with empty session ID"); - RETURN_FALSE; - } - /* set options */ if (options) { ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(options), num_idx, str_idx, value) { @@ -2941,7 +2963,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo if (name_len == progress->sname_len && memcmp(data->name, PS(session_name), name_len) == 0) { zval_dtor(&progress->sid); ZVAL_STRINGL(&progress->sid, (*data->value), value_len); - } else if (memcmp(data->name, PS(rfc1867_name), name_len + 1) == 0) { + } else if (name_len == strlen(PS(rfc1867_name)) && memcmp(data->name, PS(rfc1867_name), name_len + 1) == 0) { smart_str_free(&progress->key); smart_str_appends(&progress->key, PS(rfc1867_prefix)); smart_str_appendl(&progress->key, *data->value, value_len); diff --git a/ext/session/tests/016.phpt b/ext/session/tests/016.phpt index 82a85d2705..f23605eb47 100644 --- a/ext/session/tests/016.phpt +++ b/ext/session/tests/016.phpt @@ -22,5 +22,5 @@ session_write_close(); print "I live\n"; ?> --EXPECTF-- -Warning: session_write_close(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (123;:/really%scompletely:::/invalid;;,23123;213) in %s on line %d +Warning: session_start(): Failed to read session data: files (path: 123;:/really%scompletely:::/invalid;;,23123;213) in %s on line %d I live diff --git a/ext/session/tests/bug32330.phpt b/ext/session/tests/bug32330.phpt index fe83cc9504..98d442ae5c 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 -gc: maxlifetime = %d read: id = %s +gc: maxlifetime = %d write: id = %s, data = A|s:1:"B"; close open: path = /tmp, name = sid -gc: maxlifetime = %d read: id = %s +gc: maxlifetime = %d destroy: id = %s close open: path = /tmp, name = sid -gc: maxlifetime = %d read: id = %s +gc: maxlifetime = %d write: id = %s, data = E|s:1:"F"; close diff --git a/ext/session/tests/bug55688.phpt b/ext/session/tests/bug55688.phpt index 8db48384af..b073dc3c5c 100644 --- a/ext/session/tests/bug55688.phpt +++ b/ext/session/tests/bug55688.phpt @@ -12,4 +12,4 @@ $x = new SessionHandler; $x->gc(1); ?> --EXPECTF-- -Warning: SessionHandler::gc(): Parent session handler is not open in %s on line %d +Warning: SessionHandler::gc(): Session is not active in %s on line %d diff --git a/ext/session/tests/bug60634.phpt b/ext/session/tests/bug60634.phpt index 86dcb11526..b2f5076287 100644 --- a/ext/session/tests/bug60634.phpt +++ b/ext/session/tests/bug60634.phpt @@ -39,8 +39,17 @@ 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(). +*/ + ?> --EXPECTF-- write: goodbye cruel world +write: goodbye cruel world close: goodbye cruel world diff --git a/ext/session/tests/bug60634_error_1.phpt b/ext/session/tests/bug60634_error_1.phpt index d0733f5a5a..fa76ff522a 100644 --- a/ext/session/tests/bug60634_error_1.phpt +++ b/ext/session/tests/bug60634_error_1.phpt @@ -41,6 +41,11 @@ session_start(); session_write_close(); echo "um, hi\n"; +/* +FIXME: Something wrong. It should try to close after error, otherwise session +may keep "open" state. +*/ + ?> --EXPECTF-- write: goodbye cruel world @@ -51,3 +56,4 @@ Stack trace: #1 %s(%d): session_write_close() #2 {main} thrown in %s on line %d + diff --git a/ext/session/tests/bug61728.phpt b/ext/session/tests/bug61728.phpt index 3f8dbeb58a..2780d7b7e2 100644 --- a/ext/session/tests/bug61728.phpt +++ b/ext/session/tests/bug61728.phpt @@ -8,32 +8,34 @@ function output_html($ext) { return strlen($ext); } -function open ($save_path, $session_name) { +function open ($save_path, $session_name) { return true; -} +} -function close() { +function close() { return true; -} +} -function read ($id) { -} +function read ($id) { + return ''; +} -function write ($id, $sess_data) { +function write ($id, $sess_data) { ob_start("output_html"); echo "laruence"; ob_end_flush(); return true; -} +} -function destroy ($id) { -} +function destroy ($id) { + return true; +} -function gc ($maxlifetime) { - return true; -} +function gc ($maxlifetime) { + return true; +} -session_set_save_handler ("open", "close", "read", "write", "destroy", "gc"); +session_set_save_handler ("open", "close", "read", "write", "destroy", "gc"); session_start(); --EXPECTF-- 8 diff --git a/ext/session/tests/bug67972.phpt b/ext/session/tests/bug67972.phpt index 63ed3a95b8..92c3044ac5 100644 --- a/ext/session/tests/bug67972.phpt +++ b/ext/session/tests/bug67972.phpt @@ -7,4 +7,5 @@ Bug #67972: SessionHandler Invalid memory read create_sid() (new SessionHandler)->create_sid(); --EXPECTF-- -Fatal error: SessionHandler::create_sid(): Cannot call default session handler in %s on line %d +Warning: SessionHandler::create_sid(): Session is not active in %s on line %d + diff --git a/ext/session/tests/bug68063.phpt b/ext/session/tests/bug68063.phpt index d3da470d06..ec3a70d156 100644 --- a/ext/session/tests/bug68063.phpt +++ b/ext/session/tests/bug68063.phpt @@ -3,18 +3,22 @@ Bug #68063 (Empty session IDs do still start sessions) --SKIPIF-- <?php include('skipif.inc'); ?> --INI-- +session.use_strict_mode=0 +session.hash_function=1 +session.hash_bits_per_character=4 --FILE-- <?php +// Empty session ID may happen by browser bugs + // Could also be set with a cookie like "PHPSESSID=; path=/" session_id(''); -// Will still start the session and return true +// Start the session with empty string should result in new session ID var_dump(session_start()); -// Returns an empty string +// Returns newly created session ID var_dump(session_id()); ?> --EXPECTF-- -Warning: session_start(): Cannot start session with empty session ID in %s on line %d -bool(false) -string(0) "" +bool(true) +string(40) "%s" diff --git a/ext/session/tests/bug69111.phpt b/ext/session/tests/bug69111.phpt new file mode 100644 index 0000000000..75b78f01ac --- /dev/null +++ b/ext/session/tests/bug69111.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #69111 Crash in SessionHandler::read() +--SKIPIF-- +--XFAIL-- +It is still a leak +<?php include('skipif.inc'); ?> +--FILE-- +<?php +$sh = new SessionHandler; +session_set_save_handler($sh); + +$savePath = ini_get('session.save_path'); +$sessionName = ini_get('session.name'); + +// session_start(); // Uncommenting this makes it not crash when reading the session (see below), but it will not return any data. + +$sh->open($savePath, $sessionName); +$sh->write("foo", "bar"); +var_dump($sh->read(@$id)); +?> +--EXPECTF-- +bool(false) diff --git a/ext/session/tests/bug70133.phpt b/ext/session/tests/bug70133.phpt new file mode 100644 index 0000000000..3e019e483b --- /dev/null +++ b/ext/session/tests/bug70133.phpt @@ -0,0 +1,41 @@ +--TEST-- +Bug #70133 (Extended SessionHandler::read is ignoring $session_id when calling parent) +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.save_handler=files +session.save_path= +session.use_strict_mode=0 +--FILE-- +<?php + +class CustomReadHandler extends \SessionHandler { + + public function read($session_id) { + return parent::read('mycustomsession'); + } +} + +ob_start(); + +session_set_save_handler(new CustomReadHandler(), true); + +session_id('mycustomsession'); +session_start(); +$_SESSION['foo'] = 'hoge'; +var_dump(session_id()); +session_commit(); + +session_id('otherid'); +session_start(); +var_dump($_SESSION); +var_dump(session_id()); + +?> +--EXPECT-- +string(15) "mycustomsession" +array(1) { + ["foo"]=> + string(4) "hoge" +} +string(7) "otherid" diff --git a/ext/session/tests/bug71186.phpt b/ext/session/tests/bug71186.phpt new file mode 100644 index 0000000000..5eeba6035f --- /dev/null +++ b/ext/session/tests/bug71186.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #71186 session.hash_function - algorithm changes +--SKIPIF-- +<?php include('skipif.inc'); ?> +--INI-- +session.hash_function=sha512 +session.save_handler=files +--FILE-- +<?php +ob_start(); +ini_set('session.use_strict_mode', 1); + +session_start(); +$orig = session_id(); +session_regenerate_id(); +$new = session_id(); +var_dump(strlen($orig),strlen($new)); +session_commit(); + +ini_set('session.hash_function','sha1'); +session_id('invalid'); +session_start(); +$orig = session_id(); +session_regenerate_id(); +$new = session_id(); +var_dump(strlen($orig),strlen($new)); +?> +--EXPECT-- +int(128) +int(128) +int(40) +int(40) diff --git a/ext/session/tests/rfc1867_sid_invalid.phpt b/ext/session/tests/rfc1867_sid_invalid.phpt index 4dd8f1f979..a9114e3e1d 100644 --- a/ext/session/tests/rfc1867_sid_invalid.phpt +++ b/ext/session/tests/rfc1867_sid_invalid.phpt @@ -47,13 +47,13 @@ session_destroy(); --EXPECTF-- Warning: Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0 -Warning: Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0 +Warning: Unknown: Failed to read session data: files (path: ) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0 Warning: Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0 -Warning: Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0 +Warning: Unknown: Failed to read session data: files (path: ) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0 string(%d) "%s" diff --git a/ext/session/tests/session_save_path_variation2.phpt b/ext/session/tests/session_save_path_variation2.phpt index 4cf44b75a4..60675aec3c 100644 --- a/ext/session/tests/session_save_path_variation2.phpt +++ b/ext/session/tests/session_save_path_variation2.phpt @@ -33,8 +33,12 @@ ob_end_flush(); string(5) "/blah" Warning: session_start(): open(%sblah%e%s, O_RDWR) failed: No such file or directory (2) in %s on line %d -bool(true) + +Warning: session_start(): Failed to read session data: files (path: %sblah) in %s on line %d +bool(false) string(5) "/blah" -bool(true) + +Warning: session_destroy(): Trying to destroy uninitialized session in %s on line %d +bool(false) string(5) "/blah" Done diff --git a/ext/session/tests/session_save_path_variation3.phpt b/ext/session/tests/session_save_path_variation3.phpt index b064f30183..1d290d95b3 100644 --- a/ext/session/tests/session_save_path_variation3.phpt +++ b/ext/session/tests/session_save_path_variation3.phpt @@ -33,8 +33,12 @@ ob_end_flush(); string(5) "/blah" Warning: session_start(): open(%s, O_RDWR) failed: No such file or directory (2) in %s on line %d -bool(true) + +Warning: session_start(): Failed to read session data: files (path: %sblah) in %s on line %d +bool(false) string(5) "/blah" -bool(true) + +Warning: session_destroy(): Trying to destroy uninitialized session in %s on line %d +bool(false) string(5) "/blah" Done diff --git a/ext/session/tests/session_set_save_handler_class_002.phpt b/ext/session/tests/session_set_save_handler_class_002.phpt index b75a7e6390..880bc33425 100644 --- a/ext/session/tests/session_set_save_handler_class_002.phpt +++ b/ext/session/tests/session_set_save_handler_class_002.phpt @@ -34,7 +34,7 @@ class MySession2 extends SessionHandler { } public function read($id) { - return @file_get_contents($this->path . $id); + return (string)@file_get_contents($this->path . $id); } public function write($id, $data) { diff --git a/ext/session/tests/session_set_save_handler_class_005.phpt b/ext/session/tests/session_set_save_handler_class_005.phpt index 5be735306a..1b8c1ce645 100644 --- a/ext/session/tests/session_set_save_handler_class_005.phpt +++ b/ext/session/tests/session_set_save_handler_class_005.phpt @@ -33,7 +33,7 @@ class MySession6 extends SessionHandler { $handler = new MySession6; session_set_save_handler($handler); -session_start(); +var_dump(session_start()); var_dump(session_id(), ini_get('session.save_handler'), $_SESSION); @@ -45,13 +45,12 @@ session_unset(); *** Testing session_set_save_handler() : incomplete implementation *** Warning: SessionHandler::read(): Parent session handler is not open in %ssession_set_save_handler_class_005.php on line %d + +Warning: SessionHandler::close(): Parent session handler is not open in %ssession_set_save_handler_class_005.php on line %d + +Warning: session_start(): Failed to read session data: user (%s) in %ssession_set_save_handler_class_005.php on line %d +bool(false) string(%d) "%s" string(4) "user" array(0) { } - -Warning: SessionHandler::write(): Parent session handler is not open in %ssession_set_save_handler_class_005.php on line %d - -Warning: session_write_close(): Failed to write session data %s in %ssession_set_save_handler_class_005.php on line %d - -Warning: SessionHandler::close(): Parent session handler is not open in %ssession_set_save_handler_class_005.php on line %d diff --git a/ext/session/tests/session_set_save_handler_class_012.phpt b/ext/session/tests/session_set_save_handler_class_012.phpt index 91e751bdfc..0ce03f865e 100644 --- a/ext/session/tests/session_set_save_handler_class_012.phpt +++ b/ext/session/tests/session_set_save_handler_class_012.phpt @@ -38,7 +38,7 @@ class MySession extends SessionHandler { $oldHandler = ini_get('session.save_handler'); $handler = new MySession; session_set_save_handler($handler); -session_start(); +var_dump(session_start()); var_dump(session_id(), $oldHandler, ini_get('session.save_handler'), $handler->i, $_SESSION); @@ -50,15 +50,14 @@ Warning: SessionHandler::open() expects exactly 2 parameters, 0 given in %s on l Read %s Warning: SessionHandler::read(): Parent session handler is not open in %s on line %d + +Warning: SessionHandler::close(): Parent session handler is not open in %s on line %d + +Warning: session_start(): Failed to read session data: user (%s) in %s on line %d +bool(false) string(%d) "%s" string(5) "files" string(4) "user" int(2) array(0) { } - -Warning: SessionHandler::write(): Parent session handler is not open in Unknown on line 0 - -Warning: session_write_close(): Failed to write session data %s in %s on line %d - -Warning: SessionHandler::close(): Parent session handler is not open in Unknown on line 0 diff --git a/ext/session/tests/session_set_save_handler_class_016.phpt b/ext/session/tests/session_set_save_handler_class_016.phpt index 521bd86f31..4095813c9d 100644 --- a/ext/session/tests/session_set_save_handler_class_016.phpt +++ b/ext/session/tests/session_set_save_handler_class_016.phpt @@ -10,10 +10,10 @@ session.name=PHPSESSID ob_start(); -/* +/* * Prototype : bool session_set_save_handler(SessionHandlerInterface $handler [, bool $register_shutdown_function = true]) * Description : Sets user-level session storage functions - * Source code : ext/session/session.c + * Source code : ext/session/session.c */ echo "*** Testing session_set_save_handler() function: class with create_sid ***\n"; @@ -34,7 +34,7 @@ class MySession2 extends SessionHandler { } public function read($id) { - return @file_get_contents($this->path . $id); + return (string)@file_get_contents($this->path . $id); } public function write($id, $data) { diff --git a/ext/session/tests/session_set_save_handler_class_017.phpt b/ext/session/tests/session_set_save_handler_class_017.phpt index 6f42d7809a..b8e7d7a7ad 100644 --- a/ext/session/tests/session_set_save_handler_class_017.phpt +++ b/ext/session/tests/session_set_save_handler_class_017.phpt @@ -34,7 +34,7 @@ class MySession2 extends SessionHandler { } public function read($id) { - return @file_get_contents($this->path . $id); + return (string)@file_get_contents($this->path . $id); } public function write($id, $data) { diff --git a/ext/session/tests/session_set_save_handler_error4.phpt b/ext/session/tests/session_set_save_handler_error4.phpt index be3429b084..4267195ee1 100644 --- a/ext/session/tests/session_set_save_handler_error4.phpt +++ b/ext/session/tests/session_set_save_handler_error4.phpt @@ -24,7 +24,7 @@ session_set_save_handler("callback", "callback", "callback", "echo", "callback", session_set_save_handler("callback", "callback", "callback", "callback", "echo", "callback"); session_set_save_handler("callback", "callback", "callback", "callback", "callback", "echo"); session_set_save_handler("callback", "callback", "callback", "callback", "callback", "callback"); -session_start(); +var_dump(session_start()); ob_end_flush(); ?> --EXPECTF-- @@ -39,3 +39,6 @@ Warning: session_set_save_handler(): Argument 4 is not a valid callback in %s on Warning: session_set_save_handler(): Argument 5 is not a valid callback in %s on line %d Warning: session_set_save_handler(): Argument 6 is not a valid callback in %s on line %d + +Warning: session_start(): Failed to read session data: user (%s) in %s on line %d +bool(false) diff --git a/ext/session/tests/session_set_save_handler_iface_001.phpt b/ext/session/tests/session_set_save_handler_iface_001.phpt index 03ee42865c..6943d59cbe 100644 --- a/ext/session/tests/session_set_save_handler_iface_001.phpt +++ b/ext/session/tests/session_set_save_handler_iface_001.phpt @@ -34,7 +34,7 @@ class MySession2 implements SessionHandlerInterface { } public function read($id) { - return @file_get_contents($this->path . $id); + return (string)@file_get_contents($this->path . $id); } public function write($id, $data) { diff --git a/ext/session/tests/session_set_save_handler_iface_002.phpt b/ext/session/tests/session_set_save_handler_iface_002.phpt index 40c9ac6825..204d88c785 100644 --- a/ext/session/tests/session_set_save_handler_iface_002.phpt +++ b/ext/session/tests/session_set_save_handler_iface_002.phpt @@ -43,7 +43,7 @@ class MySession2 implements MySessionHandlerInterface { } public function read($id) { - return @file_get_contents($this->path . $id); + return (string)@file_get_contents($this->path . $id); } public function write($id, $data) { diff --git a/ext/session/tests/session_set_save_handler_variation4.phpt b/ext/session/tests/session_set_save_handler_variation4.phpt index 67aa70c4af..a711fdea59 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,12 +67,20 @@ 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 -Read [%s,%s] -array(0) { +array(3) { + ["Blah"]=> + string(12) "Hello World!" + ["Foo"]=> + bool(false) + ["Guff"]=> + int(1234567890) } Destroy [%s,%s] + +Warning: unlink(%s): No such file or directory in %s on line %s 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 4c1687cac6..6ad600e4d1 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,10 +88,12 @@ 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(%s): No such file or directory in %s on line %d Close [%s,PHPSESSID] bool(true) diff --git a/ext/session/tests/sessionhandler_open_001.phpt b/ext/session/tests/sessionhandler_open_001.phpt index 6ade9e00a5..e6e913a6a5 100644 --- a/ext/session/tests/sessionhandler_open_001.phpt +++ b/ext/session/tests/sessionhandler_open_001.phpt @@ -16,4 +16,11 @@ print "Done!\n"; ?> --EXPECTF-- +Warning: SessionHandler::open(): Session is not active in %s on line 5 + +Warning: SessionHandler::open(): Session is not active in %s on line 6 + +Warning: SessionHandler::open(): Session is not active in %s on line 7 + +Warning: SessionHandler::open(): Session is not active in %s on line 8 Done! |
