Skip to content

Commit 6985aff

Browse files
committed
Fix phpGH-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 phpGH-13689.
1 parent 809446d commit 6985aff

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ PHP NEWS
2727
. Fixed bug GH-13544 (Pre-PHP 8.2 compatibility for mt_srand with unknown
2828
modes). (timwolla)
2929

30+
- Session:
31+
. Fixed bug GH-13680 (Segfault with session_decode and compilation error).
32+
(nielsdos)
33+
3034
- Sockets:
3135
. Fixed bug GH-13604 (socket_getsockname returns random characters in the end
3236
of the socket name). (David Carlier)

ext/session/session.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,17 @@ static zend_result php_session_decode(zend_string *data) /* {{{ */
259259
php_error_docref(NULL, E_WARNING, "Unknown session.serialize_handler. Failed to decode session object");
260260
return FAILURE;
261261
}
262+
zend_result result = SUCCESS;
262263
zend_try {
263264
if (PS(serializer)->decode(ZSTR_VAL(data), ZSTR_LEN(data)) == FAILURE) {
264265
php_session_cancel_decode();
265-
return FAILURE;
266+
result = FAILURE;
266267
}
267268
} zend_catch {
268269
php_session_cancel_decode();
269270
zend_bailout();
270271
} zend_end_try();
271-
return SUCCESS;
272+
return result;
272273
}
273274
/* }}} */
274275

ext/session/tests/gh13680.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
GH-13680 (Segfault with session_decode and compilation error)
3+
--EXTENSIONS--
4+
session
5+
--SKIPIF--
6+
<?php include('skipif.inc'); ?>
7+
--INI--
8+
session.use_cookies=0
9+
session.use_strict_mode=0
10+
session.cache_limiter=
11+
session.serialize_handler=php_serialize
12+
session.save_handler=files
13+
error_reporting=E_ALL
14+
--FILE--
15+
<?php
16+
session_start();
17+
session_decode('foo');
18+
class Test extends DateTime {
19+
public static function createFromFormat($format, $datetime, $timezone = null): Wrong {}
20+
}
21+
?>
22+
--EXPECTF--
23+
Warning: session_decode(): Failed to decode session object. Session has been destroyed in %s on line %d
24+
25+
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

0 commit comments

Comments
 (0)