Skip to content

Commit 26baf54

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: fix #78624: session_gc return value for user defined session handlers
2 parents 4731f57 + 74ca3a5 commit 26baf54

File tree

4 files changed

+85
-9
lines changed

4 files changed

+85
-9
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ PHP NEWS
5050
(krakjoe)
5151
. Fixed bug #77805 (phpdbg build fails when readline is shared). (krakjoe)
5252

53+
- Session:
54+
. Fixed bug #78624 (session_gc return value for user defined session
55+
handlers). (bshaffer)
56+
5357
- SimpleXML:
5458
. Fixed bug #75245 (Don't set content of elements with only whitespaces).
5559
(eriklundin)

ext/session/mod_user.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,15 @@ PS_GC_FUNC(user)
187187
ps_call_handler(&PSF(gc), 1, args, &retval);
188188

189189
if (Z_TYPE(retval) == IS_LONG) {
190-
return Z_LVAL(retval);
191-
}
192-
193-
/* This is for older API compatibility */
194-
if (Z_TYPE(retval) == IS_TRUE) {
195-
return 1;
190+
*nrdels = Z_LVAL(retval);
191+
} else if (Z_TYPE(retval) == IS_TRUE) {
192+
/* This is for older API compatibility */
193+
*nrdels = 1;
194+
} else {
195+
/* Anything else is some kind of error */
196+
*nrdels = -1; // Error
196197
}
197-
198-
/* Anything else is some kind of error */
199-
return -1; // Error
198+
return *nrdels;
200199
}
201200

202201
PS_CREATE_SID_FUNC(user)

ext/session/tests/bug78624.phpt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--TEST--
2+
Test session_set_save_handler() : session_gc() returns the number of deleted records.
3+
--INI--
4+
session.name=PHPSESSID
5+
session.save_handler=files
6+
--SKIPIF--
7+
<?php include('skipif.inc'); ?>
8+
--FILE--
9+
<?php
10+
11+
ob_start();
12+
13+
/*
14+
* Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true])
15+
* Description : Sets user-level session storage functions
16+
* Source code : ext/session/session.c
17+
*/
18+
19+
echo "*** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***\n";
20+
21+
class MySession implements SessionHandlerInterface {
22+
public function open($path, $name) {
23+
echo 'Open', "\n";
24+
return true;
25+
}
26+
public function read($key) {
27+
echo 'Read ', session_id(), "\n";
28+
return '';
29+
}
30+
public function write($key, $data) {
31+
echo 'Write ', session_id(), "\n";
32+
return true;
33+
}
34+
public function close() {
35+
echo 'Close ', session_id(), "\n";
36+
return true;
37+
}
38+
public function destroy($key) {
39+
echo 'Destroy ', session_id(), "\n";
40+
return true;
41+
}
42+
public function gc($ts) {
43+
echo 'Garbage collect', "\n";
44+
return 1;
45+
}
46+
}
47+
48+
$handler = new MySession;
49+
session_set_save_handler($handler);
50+
session_start();
51+
var_dump(session_gc());
52+
session_write_close();
53+
54+
--EXPECTF--
55+
*** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***
56+
Open
57+
Read %s
58+
Garbage collect
59+
int(1)
60+
Write %s
61+
Close %s

ext/session/tests/session_set_save_handler_basic.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ var_dump($_SESSION);
4949
$_SESSION['Bar'] = 'Foo';
5050
session_write_close();
5151

52+
echo "Garbage collection..\n";
53+
session_id($session_id);
54+
session_start();
55+
var_dump(session_gc());
56+
session_write_close();
57+
5258
echo "Cleanup..\n";
5359
session_id($session_id);
5460
session_start();
@@ -101,6 +107,12 @@ array(3) {
101107
}
102108
Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;Bar|s:3:"Foo";]
103109
Close [%s,PHPSESSID]
110+
Garbage collection..
111+
Open [%s,PHPSESSID]
112+
Read [%s,%s]
113+
int(0)
114+
Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;Bar|s:3:"Foo";]
115+
Close [%s,PHPSESSID]
104116
Cleanup..
105117
Open [%s,PHPSESSID]
106118
Read [%s,%s]

0 commit comments

Comments
 (0)