summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Watkins <krakjoe@php.net>2019-10-04 06:16:02 +0200
committerJoe Watkins <krakjoe@php.net>2019-10-04 06:16:18 +0200
commit74ca3a5cad36fe1ba4a0815df8409abfc99d0178 (patch)
tree39063c74f03cb0190211729fe6ea50c5985fbba6
parent8069e1522d867d5f2eb098dbdea75008474d9b3d (diff)
parentf45eb353d1fe1bf74c92bec88b7e1e1ea3604345 (diff)
downloadphp-git-74ca3a5cad36fe1ba4a0815df8409abfc99d0178.tar.gz
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: fix #78624: session_gc return value for user defined session handlers
-rw-r--r--NEWS4
-rw-r--r--ext/session/mod_user.c17
-rw-r--r--ext/session/tests/bug78624.phpt61
-rw-r--r--ext/session/tests/session_set_save_handler_basic.phpt12
4 files changed, 85 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index 38f7a9fddc..8776ab5208 100644
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,10 @@ PHP NEWS
- OpenSSL:
. Changed the default config path (Windows only). (cmb)
+- Session:
+ . Fixed bug #78624 (session_gc return value for user defined session
+ handlers). (bshaffer)
+
- Standard:
. Fixed bug #78549 (Stack overflow due to nested serialized input). (Nikita)
diff --git a/ext/session/mod_user.c b/ext/session/mod_user.c
index 981e920bc1..b66ac26c81 100644
--- a/ext/session/mod_user.c
+++ b/ext/session/mod_user.c
@@ -189,16 +189,15 @@ PS_GC_FUNC(user)
ps_call_handler(&PSF(gc), 1, args, &retval);
if (Z_TYPE(retval) == IS_LONG) {
- return Z_LVAL(retval);
- }
-
- /* This is for older API compatibility */
- if (Z_TYPE(retval) == IS_TRUE) {
- return 1;
+ *nrdels = Z_LVAL(retval);
+ } else if (Z_TYPE(retval) == IS_TRUE) {
+ /* This is for older API compatibility */
+ *nrdels = 1;
+ } else {
+ /* Anything else is some kind of error */
+ *nrdels = -1; // Error
}
-
- /* Anything else is some kind of error */
- return -1; // Error
+ return *nrdels;
}
PS_CREATE_SID_FUNC(user)
diff --git a/ext/session/tests/bug78624.phpt b/ext/session/tests/bug78624.phpt
new file mode 100644
index 0000000000..9055b5af7b
--- /dev/null
+++ b/ext/session/tests/bug78624.phpt
@@ -0,0 +1,61 @@
+--TEST--
+Test session_set_save_handler() : session_gc() returns the number of deleted records.
+--INI--
+session.name=PHPSESSID
+session.save_handler=files
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--FILE--
+<?php
+
+ob_start();
+
+/*
+ * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true])
+ * Description : Sets user-level session storage functions
+ * Source code : ext/session/session.c
+ */
+
+echo "*** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***\n";
+
+class MySession implements SessionHandlerInterface {
+ public function open($path, $name) {
+ echo 'Open', "\n";
+ return true;
+ }
+ public function read($key) {
+ echo 'Read ', session_id(), "\n";
+ return '';
+ }
+ public function write($key, $data) {
+ echo 'Write ', session_id(), "\n";
+ return true;
+ }
+ public function close() {
+ echo 'Close ', session_id(), "\n";
+ return true;
+ }
+ public function destroy($key) {
+ echo 'Destroy ', session_id(), "\n";
+ return true;
+ }
+ public function gc($ts) {
+ echo 'Garbage collect', "\n";
+ return 1;
+ }
+}
+
+$handler = new MySession;
+session_set_save_handler($handler);
+session_start();
+var_dump(session_gc());
+session_write_close();
+
+--EXPECTF--
+*** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***
+Open
+Read %s
+Garbage collect
+int(1)
+Write %s
+Close %s
diff --git a/ext/session/tests/session_set_save_handler_basic.phpt b/ext/session/tests/session_set_save_handler_basic.phpt
index c1c763f68b..2a9b511aba 100644
--- a/ext/session/tests/session_set_save_handler_basic.phpt
+++ b/ext/session/tests/session_set_save_handler_basic.phpt
@@ -49,6 +49,12 @@ var_dump($_SESSION);
$_SESSION['Bar'] = 'Foo';
session_write_close();
+echo "Garbage collection..\n";
+session_id($session_id);
+session_start();
+var_dump(session_gc());
+session_write_close();
+
echo "Cleanup..\n";
session_id($session_id);
session_start();
@@ -101,6 +107,12 @@ array(3) {
}
Write [%s,%s,Blah|s:12:"Hello World!";Foo|b:0;Guff|i:1234567890;Bar|s:3:"Foo";]
Close [%s,PHPSESSID]
+Garbage collection..
+Open [%s,PHPSESSID]
+Read [%s,%s]
+int(0)
+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]