Skip to content

Commit 354a1c2

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
2 parents d2d1a50 + 3b53d28 commit 354a1c2

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

ext/mbstring/mbstring.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,7 +3134,7 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
31343134
{
31353135
HashTable *output, *chash;
31363136
zend_long idx;
3137-
zend_string *key, *key_tmp;
3137+
zend_string *key;
31383138
zval *entry, entry_tmp;
31393139
size_t ckey_len, cval_len;
31403140
char *ckey, *cval;
@@ -3154,7 +3154,8 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
31543154
/* convert key */
31553155
if (key) {
31563156
ckey = php_mb_convert_encoding(ZSTR_VAL(key), ZSTR_LEN(key), _to_encoding, _from_encodings, &ckey_len);
3157-
key_tmp = zend_string_init(ckey, ckey_len, 0);
3157+
key = zend_string_init(ckey, ckey_len, 0);
3158+
efree(ckey);
31583159
}
31593160
/* convert value */
31603161
ZEND_ASSERT(entry);
@@ -3182,13 +3183,14 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
31823183
case IS_OBJECT:
31833184
default:
31843185
if (key) {
3185-
efree(key_tmp);
3186+
zend_string_release(key);
31863187
}
31873188
php_error_docref(NULL, E_WARNING, "Object is not supported");
31883189
continue;
31893190
}
31903191
if (key) {
3191-
zend_hash_add(output, key_tmp, &entry_tmp);
3192+
zend_hash_add(output, key, &entry_tmp);
3193+
zend_string_release(key);
31923194
} else {
31933195
zend_hash_index_add(output, idx, &entry_tmp);
31943196
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
mb_convert_encoding() shouldn't leak keys
3+
--FILE--
4+
<?php
5+
6+
$x = "x";
7+
$array = ["foo" . $x => "bar"];
8+
mb_convert_encoding($array, 'UTF-8', 'UTF-8');
9+
var_dump($array);
10+
11+
?>
12+
--EXPECT--
13+
array(1) {
14+
["foox"]=>
15+
string(3) "bar"
16+
}

0 commit comments

Comments
 (0)