Followup fix to custom session save handlers

2d9885c introduced some regressions.  This addresses those.

  * Don't throw return type notice or session write failure when in an exception
  * Fix tests to properly return true/false since null is no longer falsy/successy
  * Rerecord a few tests to accomodate difference in raised warnings
This commit is contained in:
Sara Golemon 2014-07-07 12:19:11 -07:00
parent 888fb3323e
commit 7c2489751c
14 changed files with 34 additions and 16 deletions

View File

@ -79,7 +79,10 @@ static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC)
/* BC for clever users - Deprecate me */ \
ret = SUCCESS; \
} else { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session callback expects true/false return value"); \
if (!EG(exception)) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, \
"Session callback expects true/false return value"); \
} \
ret = FAILURE; \
} \
zval_ptr_dtor(&retval); \

View File

@ -566,7 +566,7 @@ static void php_session_save_current_state(TSRMLS_D) /* {{{ */
}
}
if (ret == FAILURE) {
if ((ret == FAILURE) && !EG(exception)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write session data (%s). Please "
"verify that the current setting of session.save_path "
"is correct (%s)",

View File

@ -16,6 +16,7 @@ function open($save_path, $session_name) {
function close() {
echo "close: goodbye cruel world\n";
return true;
}
function read($id) {

View File

@ -16,6 +16,7 @@ function open($save_path, $session_name) {
function close() {
echo "close: goodbye cruel world\n";
return true;
}
function read($id) {

View File

@ -31,7 +31,7 @@ function write($id, $session_data) {
if ($fp = fopen($session_file, "w")) {
$return = fwrite($fp, $session_data);
fclose($fp);
return $return;
return (bool)$return;
}
return false;
}
@ -40,7 +40,8 @@ function destroy($id) {
global $session_save_path, $name;
echo "Destroy [${session_save_path},${id}]\n";
$session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id;
return unlink($session_file);
unlink($session_file);
return true;
}
function gc($maxlifetime) {

View File

@ -21,11 +21,11 @@ function open($save_path, $session_name) {
throw new Exception("Stop...!");
}
function close() { }
function read($id) { }
function write($id, $session_data) { }
function destroy($id) { }
function gc($maxlifetime) { }
function close() { return true; }
function read($id) { return ''; }
function write($id, $session_data) { return true; }
function destroy($id) { return true; }
function gc($maxlifetime) { return true; }
var_dump(session_module_name("files"));
session_set_save_handler("open", "close", "read", "write", "destroy", "gc");
@ -41,9 +41,11 @@ ob_end_flush();
string(%d) "%s"
string(4) "user"
Fatal error: Uncaught exception 'Exception' with message 'Stop...!' in %s:%d
Warning: Uncaught exception 'Exception' with message 'Stop...!' in %s:%d
Stack trace:
#0 [internal function]: open('', 'PHPSESSID')
#1 %s(%d): session_start()
#2 {main}
thrown in %s on line %d
Fatal error: session_start(): Failed to initialize storage module: %s in %s/session_module_name_variation3.php on line %d

View File

@ -38,11 +38,12 @@ class MySession2 extends SessionHandler {
}
public function write($id, $data) {
return file_put_contents($this->path . $id, $data);
return (bool)file_put_contents($this->path . $id, $data);
}
public function destroy($id) {
@unlink($this->path . $id);
return true;
}
public function gc($maxlifetime) {

View File

@ -52,4 +52,6 @@ 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

@ -24,7 +24,9 @@ class MySession extends SessionHandler {
public function open($path, $name) {
++$this->i;
echo 'Open ', session_id(), "\n";
return parent::open();
// This test was written for broken return value handling
// Mimmick what was actually being tested by returning true here
return (null === parent::open());
}
public function read($key) {
++$this->i;
@ -57,4 +59,6 @@ array(0) {
Warning: Unknown: Parent session handler is not open in Unknown on line 0
Warning: Unknown: Failed to write session data %s in %s on line %d
Warning: Unknown: Parent session handler is not open in Unknown on line 0

View File

@ -38,7 +38,7 @@ class MySession2 extends SessionHandler {
}
public function write($id, $data) {
return file_put_contents($this->path . $id, $data);
return (bool)file_put_contents($this->path . $id, $data);
}
public function destroy($id) {

View File

@ -34,9 +34,11 @@ ob_end_flush();
--EXPECTF--
*** Testing session_set_save_handler() : error functionality ***
Fatal error: Uncaught exception 'Exception' with message 'Do something bad..!' in %s:%d
Warning: Uncaught exception 'Exception' with message 'Do something bad..!' in %s:%d
Stack trace:
#0 [internal function]: open('', 'PHPSESSID')
#1 %s(%d): session_start()
#2 {main}
thrown in %s on line %d
Fatal error: session_start(): Failed to initialize storage module: %s in %ssession_set_save_handler_error3.php on line %d

View File

@ -15,7 +15,7 @@ ob_start();
echo "*** Testing session_set_save_handler() : error functionality ***\n";
function callback() { }
function callback() { return true; }
session_set_save_handler("callback", "callback", "callback", "callback", "callback", "callback");
session_set_save_handler("callback", "echo", "callback", "callback", "callback", "callback");

View File

@ -38,7 +38,7 @@ class MySession2 implements SessionHandlerInterface {
}
public function write($id, $data) {
return file_put_contents($this->path . $id, $data);
return (bool)file_put_contents($this->path . $id, $data);
}
public function destroy($id) {

View File

@ -24,6 +24,7 @@ echo "*** Testing session_set_save_handler() : variation ***\n";
function noisy_gc($maxlifetime) {
echo("GC [".$maxlifetime."]\n");
gc($maxlifetime);
return true;
}
require_once "save_handler.inc";