Skip to content

Fix session return types #7006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/session/mod_user_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#define PS_SANITY_CHECK \
if (PS(session_status) != php_session_active) { \
php_error_docref(NULL, E_WARNING, "Session is not active"); \
RETURN_FALSE; \
zend_throw_error(NULL, "Session is not active"); \
RETURN_THROWS(); \
} \
if (PS(default_mod) == NULL) { \
zend_throw_error(NULL, "Cannot call default session handler"); \
Expand Down
4 changes: 2 additions & 2 deletions ext/session/session.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function write(string $id, string $data);
/** @return bool */
public function destroy(string $id);

/** @return int|bool */
/** @return int|false */
public function gc(int $max_lifetime);
}

Expand Down Expand Up @@ -116,7 +116,7 @@ public function write(string $id, string $data) {}
/** @return bool */
public function destroy(string $id) {}

/** @return int|bool */
/** @return int|false */
public function gc(int $max_lifetime) {}

/** @return string */
Expand Down
2 changes: 1 addition & 1 deletion ext/session/session_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 88f428841bc3e12b949a3308d60eae80d87e563a */
* Stub hash: 4221e895bdb0c3e903b7688f79e2863fc0788cee */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_session_name, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null")
Expand Down
11 changes: 8 additions & 3 deletions ext/session/tests/bug55688.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ session.save_handler=files
<?php
ini_set('session.save_handler', 'files');
$x = new SessionHandler;
$x->gc(1);

try {
$x->gc(1);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
?>
--EXPECTF--
Warning: SessionHandler::gc(): Session is not active in %s on line %d
--EXPECT--
Session is not active
11 changes: 8 additions & 3 deletions ext/session/tests/bug67972.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ Bug #67972: SessionHandler Invalid memory read create_sid()
--FILE--
<?php

(new SessionHandler)->create_sid();
try {
(new SessionHandler)->create_sid();
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

?>
--EXPECTF--
Warning: SessionHandler::create_sid(): Session is not active in %s on line %d
--EXPECT--
Session is not active
30 changes: 21 additions & 9 deletions ext/session/tests/bug69111.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,26 @@ $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--
Warning: SessionHandler::open(): Session is not active in %s on line 10
try {
$sh->open($savePath, $sessionName);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

try {
$sh->write("foo", "bar");
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

Warning: SessionHandler::write(): Session is not active in %s on line 11
try {
$sh->read(@$id);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

Warning: SessionHandler::read(): Session is not active in %s on line 12
bool(false)
?>
--EXPECT--
Session is not active
Session is not active
Session is not active
13 changes: 12 additions & 1 deletion ext/session/tests/session_set_save_handler_closures.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var_dump(session_module_name(FALSE));
var_dump(session_module_name("blah"));
var_dump(session_module_name("foo"));

$path = __DIR__;
$path = __DIR__ . '/session_set_save_handler_closures';
@mkdir($path);
session_save_path($path);
session_set_save_handler($open_closure, $close_closure, $read_closure, $write_closure, $destroy_closure, $gc_closure);

Expand All @@ -41,7 +42,12 @@ $_SESSION['Bar'] = 'Foo';
var_dump($_SESSION);
session_write_close();

echo "Cleanup\n";
session_start();
session_destroy();

ob_end_flush();
@rmdir($path);
?>
--EXPECTF--
*** Testing session_set_save_handler() : using closures as callbacks ***
Expand Down Expand Up @@ -90,3 +96,8 @@ array(4) {
}
Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;Bar|s:3:"Foo";]
Close [%s,PHPSESSID]
Cleanup
Open [%s,PHPSESSID]
Read [%s,%s]
Destroy [%s,%s]
Close [%s,PHPSESSID]
2 changes: 1 addition & 1 deletion ext/session/tests/session_set_save_handler_variation4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ob_end_flush();
Open [%s,PHPSESSID]
Read [%s,%s]
GC [0]
2 deleted
1 deleted
array(3) {
["Blah"]=>
string(12) "Hello World!"
Expand Down
39 changes: 28 additions & 11 deletions ext/session/tests/sessionhandler_open_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,37 @@ Testing repated SessionHandler::open() calls

ini_set('session.save_handler', 'files');
$x = new SessionHandler;
$x->open('','');
$x->open('','');
$x->open('','');
$x->open('','');

print "Done!\n";
try {
$x->open('','');
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

?>
--EXPECTF--
Warning: SessionHandler::open(): Session is not active in %s on line 5
try {
$x->open('','');
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

Warning: SessionHandler::open(): Session is not active in %s on line 6
try {
$x->open('','');
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

Warning: SessionHandler::open(): Session is not active in %s on line 7
try {
$x->open('','');
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

Warning: SessionHandler::open(): Session is not active in %s on line 8
print "Done!\n";

?>
--EXPECTF--
Session is not active
Session is not active
Session is not active
Session is not active
Done!