[php-src] master: Fix GH-13680: Segfault with session_decode and compilation error
| From: | Niels Dossche | Date: | Wed, 13 Mar 2024 17:16:24 +0000 |
| Subject: | [php-src] master: Fix GH-13680: Segfault with session_decode and compilation error | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-127715@lists.php.net to get a copy of this message | ||
Author: Niels Dossche (nielsdos)
Date: 2024-03-13T17:47:25+01:00
Commit: https://github.com/php/php-src/commit/6985aff7c31d38eed968f4c47a261b67b924621c
Raw diff: https://github.com/php/php-src/commit/6985aff7c31d38eed968f4c47a261b67b924621c.diff
Fix GH-13680: Segfault with session_decode and compilation error
It's illegal to return from a bailout because that doesn't restore the
original bailout data. Return outside of it.
Test by YuanchengJiang
Closes GH-13689.
Changed paths:
A ext/session/tests/gh13680.phpt
M NEWS
M ext/session/session.c
Diff:
diff --git a/NEWS b/NEWS
index d24a8fee0a2a0..4598f8bea7502 100644
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,10 @@ PHP NEWS
. Fixed bug GH-13544 (Pre-PHP 8.2 compatibility for mt_srand with unknown
modes). (timwolla)
+- Session:
+ . Fixed bug GH-13680 (Segfault with session_decode and compilation error).
+ (nielsdos)
+
- Sockets:
. Fixed bug GH-13604 (socket_getsockname returns random characters in the end
of the socket name). (David Carlier)
diff --git a/ext/session/session.c b/ext/session/session.c
index 6b63999297205..74a0546b8490c 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -259,16 +259,17 @@ static zend_result php_session_decode(zend_string *data) /* {{{ */
php_error_docref(NULL, E_WARNING, "Unknown session.serialize_handler. Failed to decode
session object");
return FAILURE;
}
+ zend_result result = SUCCESS;
zend_try {
if (PS(serializer)->decode(ZSTR_VAL(data), ZSTR_LEN(data)) == FAILURE) {
php_session_cancel_decode();
- return FAILURE;
+ result = FAILURE;
}
} zend_catch {
php_session_cancel_decode();
zend_bailout();
} zend_end_try();
- return SUCCESS;
+ return result;
}
/* }}} */
diff --git a/ext/session/tests/gh13680.phpt b/ext/session/tests/gh13680.phpt
new file mode 100644
index 0000000000000..a95583ee34598
--- /dev/null
+++ b/ext/session/tests/gh13680.phpt
@@ -0,0 +1,25 @@
+--TEST--
+GH-13680 (Segfault with session_decode and compilation error)
+--EXTENSIONS--
+session
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--INI--
+session.use_cookies=0
+session.use_strict_mode=0
+session.cache_limiter=
+session.serialize_handler=php_serialize
+session.save_handler=files
+error_reporting=E_ALL
+--FILE--
+<?php
+session_start();
+session_decode('foo');
+class Test extends DateTime {
+ public static function createFromFormat($format, $datetime, $timezone = null): Wrong {}
+}
+?>
+--EXPECTF--
+Warning: session_decode(): Failed to decode session object. Session has been destroyed in %s on
line %d
+
+Fatal error: Could not check compatibility between Test::createFromFormat($format, $datetime,
$timezone = null): Wrong and DateTime::createFromFormat(string $format, string $datetime,
?DateTimeZone $timezone = null): DateTime|false, because class Wrong is not available in %s on line
%d