Skip to content

Commit 2964262

Browse files
committed
Promote "Session is not active" warning to exception
In normal circumstances, the session handler methods are not invoked when the session is not active. Closes GH-7006
1 parent 53b5105 commit 2964262

File tree

5 files changed

+67
-28
lines changed

5 files changed

+67
-28
lines changed

ext/session/mod_user_class.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
#define PS_SANITY_CHECK \
2121
if (PS(session_status) != php_session_active) { \
22-
php_error_docref(NULL, E_WARNING, "Session is not active"); \
23-
RETURN_FALSE; \
22+
zend_throw_error(NULL, "Session is not active"); \
23+
RETURN_THROWS(); \
2424
} \
2525
if (PS(default_mod) == NULL) { \
2626
zend_throw_error(NULL, "Cannot call default session handler"); \

ext/session/tests/bug55688.phpt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ session.save_handler=files
99
<?php
1010
ini_set('session.save_handler', 'files');
1111
$x = new SessionHandler;
12-
$x->gc(1);
12+
13+
try {
14+
$x->gc(1);
15+
} catch (Error $exception) {
16+
echo $exception->getMessage() . "\n";
17+
}
1318
?>
14-
--EXPECTF--
15-
Warning: SessionHandler::gc(): Session is not active in %s on line %d
19+
--EXPECT--
20+
Session is not active

ext/session/tests/bug67972.phpt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ Bug #67972: SessionHandler Invalid memory read create_sid()
55
--FILE--
66
<?php
77

8-
(new SessionHandler)->create_sid();
8+
try {
9+
(new SessionHandler)->create_sid();
10+
} catch (Error $exception) {
11+
echo $exception->getMessage() . "\n";
12+
}
13+
914
?>
10-
--EXPECTF--
11-
Warning: SessionHandler::create_sid(): Session is not active in %s on line %d
15+
--EXPECT--
16+
Session is not active

ext/session/tests/bug69111.phpt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,26 @@ $sessionName = ini_get('session.name');
1212

1313
// session_start(); // Uncommenting this makes it not crash when reading the session (see below), but it will not return any data.
1414

15-
$sh->open($savePath, $sessionName);
16-
$sh->write("foo", "bar");
17-
var_dump($sh->read(""));
18-
?>
19-
--EXPECTF--
20-
Warning: SessionHandler::open(): Session is not active in %s on line 10
15+
try {
16+
$sh->open($savePath, $sessionName);
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
20+
21+
try {
22+
$sh->write("foo", "bar");
23+
} catch (Error $exception) {
24+
echo $exception->getMessage() . "\n";
25+
}
2126

22-
Warning: SessionHandler::write(): Session is not active in %s on line 11
27+
try {
28+
$sh->read("");
29+
} catch (Error $exception) {
30+
echo $exception->getMessage() . "\n";
31+
}
2332

24-
Warning: SessionHandler::read(): Session is not active in %s on line 12
25-
bool(false)
33+
?>
34+
--EXPECT--
35+
Session is not active
36+
Session is not active
37+
Session is not active

ext/session/tests/sessionhandler_open_001.phpt

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,37 @@ Testing repated SessionHandler::open() calls
77

88
ini_set('session.save_handler', 'files');
99
$x = new SessionHandler;
10-
$x->open('','');
11-
$x->open('','');
12-
$x->open('','');
13-
$x->open('','');
1410

15-
print "Done!\n";
11+
try {
12+
$x->open('','');
13+
} catch (Error $exception) {
14+
echo $exception->getMessage() . "\n";
15+
}
1616

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

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

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

25-
Warning: SessionHandler::open(): Session is not active in %s on line 8
35+
print "Done!\n";
36+
37+
?>
38+
--EXPECTF--
39+
Session is not active
40+
Session is not active
41+
Session is not active
42+
Session is not active
2643
Done!

0 commit comments

Comments
 (0)