Skip to content

Commit fdfc7ea

Browse files
committed
Don't return persistent string from get_cfg_var()
This is not thread-safe.
1 parent 2017298 commit fdfc7ea

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ext/standard/basic_functions.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4690,10 +4690,19 @@ static void add_config_entries(HashTable *hash, zval *return_value);
46904690
static void add_config_entry(zend_ulong h, zend_string *key, zval *entry, zval *retval)
46914691
{
46924692
if (Z_TYPE_P(entry) == IS_STRING) {
4693+
zend_string *str = Z_STR_P(entry);
4694+
if (!ZSTR_IS_INTERNED(str)) {
4695+
if (!(GC_FLAGS(str) & GC_PERSISTENT)) {
4696+
zend_string_addref(str);
4697+
} else {
4698+
str = zend_string_init(ZSTR_VAL(str), ZSTR_LEN(str), 0);
4699+
}
4700+
}
4701+
46934702
if (key) {
4694-
add_assoc_str_ex(retval, ZSTR_VAL(key), ZSTR_LEN(key), zend_string_copy(Z_STR_P(entry)));
4703+
add_assoc_str_ex(retval, ZSTR_VAL(key), ZSTR_LEN(key), str);
46954704
} else {
4696-
add_index_str(retval, h, zend_string_copy(Z_STR_P(entry)));
4705+
add_index_str(retval, h, str);
46974706
}
46984707
} else if (Z_TYPE_P(entry) == IS_ARRAY) {
46994708
zval tmp;

0 commit comments

Comments
 (0)