Skip to content

Commit 56f4b59

Browse files
committed
Fix GH-25307: NULL ps_files deref after SessionHandler::open() on user module
1 parent 55a8c1b commit 56f4b59

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎ext/session/mod_user_class.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
#include "php.h"
1818
#include "php_session.h"
19+
#include "mod_user.h"
1920

2021
#define PS_SANITY_CHECK \
2122
if (PS(session_status) != php_session_active) { \
2223
zend_throw_error(NULL, "Session is not active"); \
2324
RETURN_THROWS(); \
2425
} \
25-
if (PS(default_mod) == NULL) { \
26+
if (PS(default_mod) == NULL || PS(default_mod) == ps_user_ptr) { \
2627
zend_throw_error(NULL, "Cannot call default session handler"); \
2728
RETURN_THROWS(); \
2829
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-25307 (NULL ps_files dereference in ps_files_close at shutdown)
3+
--EXTENSIONS--
4+
session
5+
--SKIPIF--
6+
<?php include(__DIR__ . '/../skipif.inc'); ?>
7+
--CREDITS--
8+
YuanchengJiang
9+
--FILE--
10+
<?php
11+
ob_start();
12+
session_set_save_handler(new SessionHandler(), true);
13+
ini_set("session.save_handler", "files");
14+
session_start();
15+
try {
16+
(new SessionHandler)->open("", "");
17+
} catch (Error $e) {
18+
echo $e->getMessage(), "\n";
19+
}
20+
echo "Done\n";
21+
?>
22+
--EXPECT--
23+
Cannot call default session handler
24+
Done

0 commit comments

Comments
 (0)