Merge branch 'PHP-5.6' into PHP-7.0

* PHP-5.6:
  Fixed Bug #71038 session_start() returns TRUE on failure
This commit is contained in:
Yasuo Ohgaki 2016-01-12 19:52:54 +09:00
commit 224aaf94af
15 changed files with 97 additions and 47 deletions

View file

@ -97,6 +97,7 @@ 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) /* {{{ */
@ -503,7 +504,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,6 +516,7 @@ 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;
}
@ -520,6 +525,7 @@ static void php_session_initialize(void) /* {{{ */
if (!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,7 +547,6 @@ 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();
@ -549,11 +554,11 @@ static void php_session_initialize(void) /* {{{ */
/* 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;
}
if (PS(session_vars)) {
zend_string_release(PS(session_vars));
@ -1288,11 +1293,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 {

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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) {

View file

@ -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

View file

@ -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

View file

@ -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) {

View file

@ -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) {

View file

@ -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)

View file

@ -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) {

View file

@ -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) {