Skip to content

Commit 10e02b0

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/session: Fix memory leak due to multiple exception happening during session abort
2 parents ceae788 + 0acde11 commit 10e02b0

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ PHP NEWS
1717
. Fixed bug GH-21333 (use after free when unlinking entries during iteration
1818
of a compressed phar). (David Carlier)
1919

20+
- Session:
21+
. Fix memory leak due to multiple exception happening during session abort.
22+
(arshidkv12)
23+
2024
- SNMP:
2125
. Fixed bug GH-21336 (SNMP::setSecurity() undefined behavior with
2226
NULL arguments). (David Carlier)

ext/session/session.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "ext/standard/url_scanner_ex.h"
4242
#include "ext/standard/info.h"
4343
#include "zend_smart_str.h"
44+
#include "zend_exceptions.h"
4445
#include "ext/standard/url.h"
4546
#include "ext/standard/basic_functions.h"
4647
#include "ext/standard/head.h"
@@ -1753,8 +1754,16 @@ PHPAPI php_session_status php_get_session_status(void)
17531754
static zend_result php_session_abort(void)
17541755
{
17551756
if (PS(session_status) == php_session_active) {
1756-
if (PS(mod_data) || PS(mod_user_implemented)) {
1757+
if ((PS(mod_data) || PS(mod_user_implemented)) && PS(mod)->s_close) {
1758+
zend_object *old_exception = EG(exception);
1759+
EG(exception) = NULL;
1760+
17571761
PS(mod)->s_close(&PS(mod_data));
1762+
if (!EG(exception)) {
1763+
EG(exception) = old_exception;
1764+
} else if (old_exception) {
1765+
zend_exception_set_previous(EG(exception), old_exception);
1766+
}
17581767
}
17591768
PS(session_status) = php_session_none;
17601769
return SUCCESS;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
SessionHandler::validateId must return bool
3+
--INI--
4+
session.use_strict_mode=1
5+
--EXTENSIONS--
6+
session
7+
--SKIPIF--
8+
<?php include('skipif.inc'); ?>
9+
--FILE--
10+
<?php
11+
class MySession extends SessionHandler {
12+
public function validateId($key) {
13+
return null;
14+
}
15+
}
16+
17+
$handler = new MySession();
18+
19+
try {
20+
session_set_save_handler($handler);
21+
session_start();
22+
} catch (TypeError $e) {
23+
echo $e->getMessage(), "\n";
24+
}
25+
26+
session_write_close();
27+
28+
try {
29+
session_start();
30+
} catch (Throwable $e) {
31+
echo $e->getMessage(), "\n";
32+
}
33+
?>
34+
--EXPECTF--
35+
Session id must be a string

ext/session/tests/user_session_module/session_set_save_handler_class_012.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ var_dump(session_id(), $oldHandler, ini_get('session.save_handler'), $handler->i
4343
--EXPECTF--
4444
*** Testing session_set_save_handler() : incorrect arguments for existing handler open ***
4545
Open:
46+
47+
Warning: SessionHandler::close(): Parent session handler is not open in %s on line %d
4648
SessionHandler::open() expects exactly 2 arguments, 0 given
4749

4850
Warning: Undefined global variable $_SESSION in %s on line %d

0 commit comments

Comments
 (0)