Skip to content

Commit 5ce9687

Browse files
Fix phpGH-13891: memleak and segfault when using ini_set with session.trans_sid_hosts (php#13892)
The hash tables used are allocated via the persistent allocator. When using ini_set, the allocation happens via the non-persistent allocator. When the table is then freed in GSHUTDOWN, we get a crash because the allocators are mismatched. As a side note, it is strange that this is designed this way, because it means that ini_sets persist between requests... Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
1 parent 97162e9 commit 5ce9687

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

ext/session/tests/gh13891.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-13891 (memleak and segfault when using ini_set with session.trans_sid_hosts)
3+
--INI--
4+
session.use_cookies=0
5+
session.use_only_cookies=0
6+
session.use_trans_sid=1
7+
session.trans_sid_hosts=php.net
8+
--EXTENSIONS--
9+
session
10+
--SKIPIF--
11+
<?php include('skipif.inc'); ?>
12+
--FILE--
13+
<?php
14+
// We *must* set it here because the bug only triggers on a runtime edit
15+
ini_set('session.trans_sid_hosts','php.net');
16+
?>
17+
--EXPECT--

ext/standard/url_scanner_ex.re

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ static int php_ini_on_update_hosts(zend_ini_entry *entry, zend_string *new_value
138138
}
139139
keylen = q - key;
140140
if (keylen > 0) {
141-
tmp_key = zend_string_init(key, keylen, 0);
141+
/* Note: the hash table is persistently allocated, so the strings must be too! */
142+
tmp_key = zend_string_init(key, keylen, true);
142143
zend_hash_add_empty_element(hosts, tmp_key);
143-
zend_string_release_ex(tmp_key, 0);
144+
zend_string_release_ex(tmp_key, true);
144145
}
145146
}
146147
efree(tmp);

0 commit comments

Comments
 (0)